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

BigFloatNumber represents floating point number with mantissa of an arbitrary size, and exponent.

Implementations

Returns a new number with value of 0 and precision of p bits. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns the maximum value for the specified precision p: all bits of the mantissa are set to 1, the exponent has the maximum possible value, and the sign is positive. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns the minimum value for the specified precision p: all bits of the mantissa are set to 1, the exponent has the maximum possible value, and the sign is negative. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns the minimum positive subnormal value for the specified precision p: only the least significant bit of the mantissa is set to 1, the exponent has the minimum possible value, and the sign is positive. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns a new number with value d and the precision p. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns a copy of the number with the sign reversed.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Adds d2 to self and returns the result of the operation rounded according to rm. The resulting precision is equal to the highest precision of the two operands.

Errors
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Subtracts d2 from self and returns the result of the operation rounded according to rm. The resulting precision is equal to the highest precision of the two operands.

Errors
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Adds d2 to self and returns the result of the operation. The resulting precision is equal to the full precision of the result. This operation can be used to emulate integer addition.

Errors
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Subtracts d2 from self and returns the result of the operation. The resulting precision is equal to the full precision of the result. This operation can be used to emulate integer subtraction.

Errors
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Multiplies d2 by self and returns the result of the operation rounded according to rm. The resulting precision is equal to the highest precision of the two operands.

Errors
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Multiplies d2 by self and returns the result of the operation. The resulting precision is equal to the full precision of the result. This operation can be used to emulate integer multiplication.

Errors
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Divides self by d2 and returns the result of the operation rounded according to rm. The resulting precision is equal to the highest precision of the two operands.

Errors
  • DivisionByZero: d2 is zero.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • MemoryAllocation: failed to allocate memory for mantissa.

Compares self to d2. Returns positive if self is greater than d2, negative if self is smaller than d2, 0 otherwise.

Returns the absolute value of a number.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Constructs a number with precision p from f64 value.

Errors
  • InvalidArgument: precision is incorrect or f is NaN.
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: f is Inf.

Constructs a number with precision p from f32 value.

Errors
  • InvalidArgument: precision is incorrect or f is NaN.
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: f is Inf.

Returns true if self is subnormal. A number is subnormal if the most significant bit of the mantissa is not equal to 1.

Decomposes self into raw parts. The function returns a reference to a slice of words representing mantissa, numbers of significant bits in the mantissa, sign, and exponent.

Constructs a number from the raw parts:

  • m is the mantisaa.
  • n is the number of significant bits in mantissa.
  • s is the sign.
  • e is the exponent.
Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns sign of a number.

Returns true if self is positive.

Returns true if self is negative.

Returns the exponent of self.

Returns the largest integer less than or equal to self.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns the smallest integer greater than or equal to self.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns fractional part of a number.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns integer part of a number.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Sets the exponent of self.

Returns the maximum mantissa length of self in bits.

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

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: rounding causes exponent overflow.

Generates a random normal number with precision p and an exponent within the range from exp_from to exp_to.

Errors
  • InvalidArgument: precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Clones the number.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Sets the precision of self to p. If the new precision is smaller than the existing one, the number is rounded using specified rounding mode rm.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.

Computes the reciprocal of a number. The result is rounded using the rounding mode rm.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: rounding causes exponent overflow.

Sets the sign of self.

Inverts the sign of self.

Returns the raw mantissa words of a number.

Parses the number from the string s using radix rdx, precision p, and rounding mode rm. Note, since hexadecimal digits include the character “e”, the exponent part is separated from the mantissa by “_”. For example, a number with mantissa 123abcdef and exponent 123 would be formatted as 123abcdef_e+123.

Errors
  • InvalidArgument: failed to parse input.
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.

Formats the number using radix rdx and rounding mode rm. Note, since hexadecimal digits include the character “e”, the exponent part is separated from the mantissa by “_”. For example, a number with mantissa 123abcdef and exponent 123 would be formatted as 123abcdef_e+123.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.

Computes square root of a number. The result is rounded using the rounding mode rm.

Errors
  • InvalidArgument: argument is negative.
  • MemoryAllocation: failed to allocate memory.

Computes the natural logarithm of a number. The result is rounded using the rounding mode rm.

Errors
  • InvalidArgument: the argument is zero or negative.
  • MemoryAllocation: failed to allocate memory.

Computes e to the power of self. The result is rounded using the rounding mode rm.

Errors
  • ExponentOverflow: the result is too large or too small number.
  • MemoryAllocation: failed to allocate memory.

Compute the power of self to the integer i. The result is rounded using the rounding mode rm.

Errors
  • ExponentOverflow: the result is too large or too small number.
  • MemoryAllocation: failed to allocate memory.

Computes the sine of a number. The result is rounded using the rounding mode rm.

Errors
  • MemoryAllocation: failed to allocate memory.

Computes the cosine of a number. The result is rounded using the rounding mode rm.

Errors
  • MemoryAllocation: failed to allocate memory.

Computes the tangent of a number. The result is rounded using the rounding mode rm.

Errors
  • ExponentOverflow: the result is too large or too small number.
  • MemoryAllocation: failed to allocate memory.

Computes the arcsine of a number. The result is rounded using the rounding mode rm.

Errors
  • InvalidArgument: argument is greater than 1 or smaller than -1.
  • MemoryAllocation: failed to allocate memory.

Computes the arccosine of a number. The result is rounded using the rounding mode rm.

Errors
  • InvalidArgument: argument is greater than 1 or smaller than -1.
  • MemoryAllocation: failed to allocate memory.

Computes the arctangent of a number. The result is rounded using the rounding mode rm.

Errors
  • MemoryAllocation: failed to allocate memory.

Converts an array of digits in radix rdx to BigFloatNumber with precision p. digits represents mantissa and is interpreted as a number smaller than 1 and greater or equal to 1/rdx. The first element in digits is the most significant digit. e is the exponent part of the number, such that the number can be represented as digits * rdx ^ e.

Examples
use astro_float::{BigFloatNumber, Sign, RoundingMode, Radix};
 
let g = BigFloatNumber::convert_from_radix(
    Sign::Neg, 
    &[1, 2, 3, 4, 5, 6, 7, 0], 
    3, 
    Radix::Oct, 
    64, 
    RoundingMode::None).unwrap();
 
let n = BigFloatNumber::from_f64(64, -83.591552734375).unwrap();
 
assert!(n.cmp(&g) == 0);
Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.

Converts self to radix rdx using rounding mode rm. The function returns sign, mantissa digits in radix rdx, and exponent such that the converted number can be represented as mantissa digits * rdx ^ exponent. The first element in mantissa is the most significant digit.

Examples
use astro_float::{BigFloatNumber, Sign, RoundingMode, Radix};
 
let n = BigFloatNumber::from_f64(64, 0.00012345678f64).unwrap();

let (s, m, e) = n.convert_to_radix(Radix::Dec, RoundingMode::None).unwrap();
 
assert_eq!(s, Sign::Pos);
assert_eq!(m, [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 4, 3]);
assert_eq!(e, -3);
Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.

Trait Implementations

Formats the value using the given formatter. 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 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.