Struct num_bigfloat::BigFloat
source · [−]pub struct BigFloat { /* private fields */ }Expand description
Number representation.
Implementations
sourceimpl BigFloat
impl BigFloat
sourcepub fn from_bytes(bytes: &[u8], sign: i8, exponent: i8) -> Self
pub fn from_bytes(bytes: &[u8], sign: i8, exponent: i8) -> Self
Create a BigFloat value from a sequence of bytes. Each byte must represent a decimal digit.
First byte is the most significant. The length of bytes can be any. If the length of
bytes is greater than required, then the remaining part is ignored.
If sign is negative, then the resulting BigFloat will be
negative.
Examples
let n1 = BigFloat::from_bytes(&[1,2,3,4,5,0,0,0], 1, -5);
let n2 = BigFloat::parse("123.45").unwrap();
assert!(n1.cmp(&n2) == Some(0));sourcepub fn from_f64(f: f64) -> Self
pub fn from_f64(f: f64) -> Self
Construct BigFloat from f64 value. The conversion is not guaranteed to be lossless, since BigFloat and f64 have different radix.
sourcepub fn from_f32(f: f32) -> Self
pub fn from_f32(f: f32) -> Self
Construct BigFloat from f32 value. The conversion is not guaranteed to be lossless, since BigFloat and f32 have different radix.
sourcepub fn get_mantissa_bytes(&self, bytes: &mut [u8])
pub fn get_mantissa_bytes(&self, bytes: &mut [u8])
Get BigFloat’s mantissa as bytes. Each byte represents a decimal digit.
First byte is the most significant. The length of bytes can be any. If the length of
bytes is smaller than required, then remaining part of mantissa will be omitted.
The length of mantissa can be determined using get_mantissa_len.
If self is Inf or NaN, nothing is returned.
Examples
let n = BigFloat::parse("123.45").unwrap();
let mut m = [0; 40];
n.get_mantissa_bytes(&mut m);
// compare m[0..10] to [1,2,3,4,5,0,0,0,0,0]
assert!(m[0..10].iter().zip([1,2,3,4,5,0,0,0,0,0].iter()).filter(|x| { x.0 != x.1 }).count() == 0);sourcepub fn get_mantissa_len(&self) -> usize
pub fn get_mantissa_len(&self) -> usize
Return the number of decimal positions filled in the mantissa.
If self is Inf or NaN, 0 is returned.
sourcepub fn get_sign(&self) -> i8
pub fn get_sign(&self) -> i8
Return 1 if BigFloat is positive, -1 otherwise.
If self is NaN, 0 is returned.
sourcepub fn get_exponent(&self) -> i8
pub fn get_exponent(&self) -> i8
Return exponent part.
If self is Inf or NaN, 0 is returned.
sourcepub fn set_exponent(&mut self, e: i8)
pub fn set_exponent(&mut self, e: i8)
Sets exponent part of self.
Function has no effect on Inf and NaN values.
sourcepub fn to_raw_parts(&self) -> Option<([i16; 10], i16, i8, i8)>
pub fn to_raw_parts(&self) -> Option<([i16; 10], i16, i8, i8)>
Return raw parts of BigFloat: mantissa, number of decimal positions in mantissa, sing, and
exponent.
If self is Inf or NaN, None is returned.
sourcepub fn from_raw_parts(
mantissa: [i16; 10],
mantissa_len: i16,
sign: i8,
exponent: i8
) -> Self
pub fn from_raw_parts(
mantissa: [i16; 10],
mantissa_len: i16,
sign: i8,
exponent: i8
) -> Self
Construct BigFloat from raw parts.
sourcepub fn is_inf_pos(&self) -> bool
pub fn is_inf_pos(&self) -> bool
Return true if self is positive infinity.
sourcepub fn is_inf_neg(&self) -> bool
pub fn is_inf_neg(&self) -> bool
Return true if self is negative infinity.
sourcepub fn cmp(&self, d2: &BigFloat) -> Option<i16>
pub fn cmp(&self, d2: &BigFloat) -> Option<i16>
Compare self to d2.
Returns positive if self > d2, negative if self < d2, zero if self == d2, None if self or d2 is NaN.
sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if self is positive.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if self is negative.
sourcepub fn is_subnormal(&self) -> bool
pub fn is_subnormal(&self) -> bool
Returns true if self is subnormal.
Number is considered subnormal iff not all places of mantissa are used, and exponent has minimum possible value.
sourcepub fn clamp(&self, min: &Self, max: &Self) -> Self
pub fn clamp(&self, min: &Self, max: &Self) -> Self
Restrict value of self to an interval determined by values of min and max.
Returns max if self is greater than max, min if self is less than min, and self otherwise.
If any of the arguments is NaN or min is greater than max, the function returns NaN.
sourcepub fn max(&self, d1: &Self) -> Self
pub fn max(&self, d1: &Self) -> Self
Returns value of d1 if d1 is greater than self, or the value of self otherwise.
If any of the arguments is NaN, the function returns NaN.
sourcepub fn min(&self, d1: &Self) -> Self
pub fn min(&self, d1: &Self) -> Self
Returns value of d1 if d1 is less than self, or the value of self otherwise.
If any of the arguments is NaN, the function returns NaN.
sourcepub fn signum(&self) -> Self
pub fn signum(&self) -> Self
Returns BigFloat with value -1 if self is negative, 1 if self is positive or zero.
Returns NaN If self is NaN.
sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parse the number from string s.
Function expects s to be a number in scientific format with base 10, or +-Inf, or NaN.
Examples
use num_bigfloat::BigFloat;
let n = BigFloat::parse("0.0").unwrap();
assert!(n.to_f64() == 0.0);
let n = BigFloat::parse("1.123e-123").unwrap();
assert!((n.to_f64() - 1.123e-123).abs() < f64::EPSILON);
let n = BigFloat::parse("-Inf").unwrap();
assert!(n.to_f64() == f64::NEG_INFINITY);
let n = BigFloat::parse("NaN").unwrap();
assert!(n.to_f64().is_nan());sourceimpl BigFloat
impl BigFloat
sourcepub fn round(&self, n: usize, rm: RoundingMode) -> Self
pub fn round(&self, n: usize, rm: RoundingMode) -> Self
Returns the rounded number with n decimal positions in the fractional part of the number using rounding mode rm.
sourcepub fn sin(&self) -> Self
pub fn sin(&self) -> Self
Returns sine of self. The function takes an angle in radians as an argument.
sourcepub fn cos(&self) -> Self
pub fn cos(&self) -> Self
Returns cosine of self. The function takes an angle in radians as an argument.
sourcepub fn tan(&self) -> Self
pub fn tan(&self) -> Self
Returns tangent of self. The function takes an angle in radians as an argument.
sourcepub fn asin(&self) -> Self
pub fn asin(&self) -> Self
Returns arcsine of self. Result is an angle in radians ranging from -pi/2 to pi/2.
sourcepub fn acos(&self) -> Self
pub fn acos(&self) -> Self
Returns arccosine of self. Result is an angle in radians ranging from 0 to pi.
Trait Implementations
sourceimpl AddAssign<&BigFloat> for BigFloat
impl AddAssign<&BigFloat> for BigFloat
sourcefn add_assign(&mut self, rhs: &BigFloat)
fn add_assign(&mut self, rhs: &BigFloat)
Performs the += operation. Read more
sourceimpl AddAssign<BigFloat> for BigFloat
impl AddAssign<BigFloat> for BigFloat
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the += operation. Read more
sourceimpl DivAssign<&BigFloat> for BigFloat
impl DivAssign<&BigFloat> for BigFloat
sourcefn div_assign(&mut self, rhs: &BigFloat)
fn div_assign(&mut self, rhs: &BigFloat)
Performs the /= operation. Read more
sourceimpl DivAssign<BigFloat> for BigFloat
impl DivAssign<BigFloat> for BigFloat
sourcefn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
Performs the /= operation. Read more
sourceimpl MulAssign<&BigFloat> for BigFloat
impl MulAssign<&BigFloat> for BigFloat
sourcefn mul_assign(&mut self, rhs: &BigFloat)
fn mul_assign(&mut self, rhs: &BigFloat)
Performs the *= operation. Read more
sourceimpl MulAssign<BigFloat> for BigFloat
impl MulAssign<BigFloat> for BigFloat
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the *= operation. Read more
sourceimpl PartialOrd<BigFloat> for BigFloat
impl PartialOrd<BigFloat> for BigFloat
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl SubAssign<&BigFloat> for BigFloat
impl SubAssign<&BigFloat> for BigFloat
sourcefn sub_assign(&mut self, rhs: &BigFloat)
fn sub_assign(&mut self, rhs: &BigFloat)
Performs the -= operation. Read more
sourceimpl SubAssign<BigFloat> for BigFloat
impl SubAssign<BigFloat> for BigFloat
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the -= operation. Read more
impl Copy for BigFloat
impl Eq for BigFloat
Auto Trait Implementations
impl RefUnwindSafe for BigFloat
impl Send for BigFloat
impl Sync for BigFloat
impl Unpin for BigFloat
impl UnwindSafe for BigFloat
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more