pub struct BigFloat { /* private fields */ }
Expand description

Number representation.

Implementations

Return new BigFloat with value zero.

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));

Construct BigFloat from f64 value. The conversion is not guaranteed to be lossless, since BigFloat and f64 have different radix.

Construct BigFloat from f32 value. The conversion is not guaranteed to be lossless, since BigFloat and f32 have different radix.

Convert BigFloat to f64.

Convert BigFloat to f32.

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);

Return the number of decimal positions filled in the mantissa. If self is Inf or NaN, 0 is returned.

Return 1 if BigFloat is positive, -1 otherwise. If self is NaN, 0 is returned.

Return exponent part. If self is Inf or NaN, 0 is returned.

Sets exponent part of self. Function has no effect on Inf and NaN values.

Return raw parts of BigFloat: mantissa, number of decimal positions in mantissa, sing, and exponent. If self is Inf or NaN, None is returned.

Construct BigFloat from raw parts.

Return true if self is positive infinity.

Return true if self is negative infinity.

Return true if self is infinite.

Return true if self is not a number.

Add d2 to self and return result of addition.

Subtract d2 from self and return result of subtraction.

Multiply self by d2 and return result of multiplication.

Divide self by d2 and return result of division.

Compare self to d2. Returns positive if self > d2, negative if self < d2, zero if self == d2, None if self or d2 is NaN.

Changes sign of a number to opposite.

Returns self to the power of d1.

Returns logarithm of base b of a number.

Returns true if self is positive.

Returns true if self is negative.

Returns true if self is subnormal. Number is considered subnormal iff not all places of mantissa are used, and exponent has minimum possible value.

Returns true if self is zero.

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.

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.

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.

Returns BigFloat with value -1 if self is negative, 1 if self is positive or zero. Returns NaN If self is NaN.

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());

Returns absolute value of self.

Returns integer part of self.

Returns fractional part of self.

Returns the smallest integer greater than or equal to self.

Returns the largest integer less than or equal to self.

Returns the rounded number with n decimal positions in the fractional part of the number using rounding mode rm.

Returns square root of self.

Returns cube root of self.

Returns natural logarithm of self.

Returns logarithm base 2 of self.

Returns logarithm base 10 of self.

Returns e to the power of self.

Returns sine of self. The function takes an angle in radians as an argument.

Returns cosine of self. The function takes an angle in radians as an argument.

Returns tangent of self. The function takes an angle in radians as an argument.

Returns arcsine of self. Result is an angle in radians ranging from -pi/2 to pi/2.

Returns arccosine of self. Result is an angle in radians ranging from 0 to pi.

Returns arctangent of self. Result is an angle in radians ranging from -pi/2 to pi/2.

Returns hyperbolic sine of self.

Returns hyperbolic cosine of self.

Returns hyperbolic tangent of self.

Returns inverse hyperbolic sine of self.

Returns inverse hyperbolic cosine of self.

Returns inverse hyperbolic tangent of self.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Construct BigFloat from integer value.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Returns parsed number or NAN in case of error.

The associated error which can be returned from parsing.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.