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

A finite floating point number with mantissa of an arbitrary size, an exponent, and the sign. (BigFloatNumber will be removed in the future. BigFloat should be used instead).

Implementations§

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. Precision is rounded upwards to the word size.

Examples

Code below converts -0.1234567₈ × 10₈^3₈ given in radix 8 to BigFloatNumber.

#![allow(deprecated)]
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.
  • InvalidArgument: the precision is incorrect, or digits contains unacceptable digits for given radix.

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 the mantissa is the most significant digit.

Examples
#![allow(deprecated)]
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, 2]);
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.

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

Errors
  • InvalidArgument: the 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: the 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: the 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: the precision is incorrect.
  • MemoryAllocation: failed to allocate memory for mantissa.

Returns the minimum positive normal value for the specified precision p: only the most 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: the 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: the 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 with precision p rounded according to rm. Precision is rounded upwards to the word size.

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

Subtracts d2 from self and returns the result of the operation with precision p rounded according to rm. Precision is rounded upwards to the word size.

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

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 with precision p rounded according to rm. Precision is rounded upwards to the word size.

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

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 with precision p rounded according to rm. Precision is rounded upwards to the word size.

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.
  • InvalidArgument: both self and d2 are zero or precision is incorrect.

Returns the remainder of division of |self| by |d2|. The sign of the result is set to the sign of self.

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.
  • InvalidArgument: both self and d2 are zero.

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

Compares the absolute value of self to the absolute value of 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. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: the 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. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: the 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.
  • InvalidArgument: n is larger than the number of bits in m; n is smaller than the number of bits in m, but m does not represent corresponding subnormal number mantissa; n is smaller than the number of bits in m, but e is not the minimum possible exponent; n or the size of m is too large (larger than isize::MAX / 2 + EXPONENT_MIN).

Constructs a number from the slice of words:

  • m is the mantissa.
  • s is the sign.
  • e is the exponent.
Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • InvalidArgument: size of m is larger than isize::MAX / 2 + EXPONENT_MIN.

Returns the sign of a number.

Returns true if self is positive.

Returns true if self is negative.

Returns the exponent of self.

Returns true if self is zero.

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. Note that if self is subnormal, the exponent may not change, but the mantissa will shift instead. See example below.

Examples
#![allow(deprecated)]
use astro_float::BigFloatNumber;
use astro_float::EXPONENT_MIN;

// construct a subnormal value.
let mut n = BigFloatNumber::min_positive(128).unwrap();

assert_eq!(n.get_exponent(), EXPONENT_MIN);
assert_eq!(n.get_precision(), 1);

// increase exponent.
n.set_exponent(n.get_exponent() + 1);

// the outcome for subnormal number.
assert_eq!(n.get_exponent(), EXPONENT_MIN);
assert_eq!(n.get_precision(), 2);

Returns the maximum mantissa length of self in bits regardless of whether self is normal or subnormal.

Returns the number of significant bits used in the mantissa. Normal numbers use all bits of the mantissa. Subnormal numbers use fewer bits than the mantissa can hold.

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.

Returns a random normalized (not subnormal) BigFloat number with exponent in the range from exp_from to exp_to inclusive. The sign can be positive and negative. Zero is excluded. Precision is rounded upwards to the word size. Function does not follow any specific distribution law. The intended use of this function is for testing.

Errors
  • InvalidArgument: the 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.
  • InvalidArgument: the precision is incorrect.

Computes the reciprocal of a number with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size.

Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: rounding caused exponent overflow.
  • InvalidArgument: the precision is incorrect.

Sets the sign of self.

Inverts the sign of self.

Returns the raw mantissa words of a number.

Constructs BigFloatNumber with precision p from a signed integer value i. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from an unsigned integer value u. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from a signed integer value i. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from an unsigned integer value u. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from a signed integer value i. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from an unsigned integer value u. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from a signed integer value i. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from an unsigned integer value u. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from a signed integer value i. Precision is rounded upwards to the word size.

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

Constructs BigFloatNumber with precision p from an unsigned integer value u. Precision is rounded upwards to the word size.

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

Computes the arccosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the hyperbolic arccosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

Errors
  • ExponentOverflow: the result is too large or too small number.
  • MemoryAllocation: failed to allocate memory.
  • InvalidArgument: when self < 1, or the precision is incorrect.

Computes the arcsine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the hyperbolic arcsine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the arctangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the hyperbolic arctangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

Errors
  • ExponentOverflow: the result is too large.
  • MemoryAllocation: failed to allocate memory.
  • InvalidArgument: when |self| > 1, or the precision is incorrect.

Computes the cube root of a number with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size.

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

Computes the cosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the hyperbolic cosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the natural logarithm of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the logarithm base 2 of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the logarithm base 10 of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the logarithm base n of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: the argument is zero or negative, or the precision is incorrect.
  • MemoryAllocation: failed to allocate memory.
  • DivisionByZero: n = 1

Computes e to the power of self with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Compute the power of self to the integer n with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size.

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

Compute the power of self to the n with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

Errors
  • ExponentOverflow: the result is too large or too small number.
  • MemoryAllocation: failed to allocate memory.
  • InvalidArgument: self is negative, or the precision is incorrect.

Computes the sine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

sine using series

Computes the hyperbolic sine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the square root of a number with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size.

Errors
  • InvalidArgument: argument is negative, or the precision is incorrect.
  • MemoryAllocation: failed to allocate memory.

Computes the tangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

Computes the hyperbolic tangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size.

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

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 or precision is incorrect.
  • 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.

Trait Implementations§

Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Serialize this value into the given Serde serializer. 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.