pub struct Repr<const BASE: Word> { /* private fields */ }
Expand description

Underlying representation of an arbitrary precision floating number.

The floating point number is represented as significand * base^exponent, where the type of the significand is IBig, and the type of exponent is isize. The representation is always normalized (nonzero signficand is not divisible by the base, or zero signficand with zero exponent).

When it’s used together with a Context, its precision will be limited so that |signficand| < base^precision. However, the precision limit is not always enforced. In rare cases, the significand can have one more digit than the precision limit.

Infinity

This struct supports representing the infinity, but the infinity is only supposed to be used as sentinels. That is, only equality test and comparison are implemented for the infinity. Any other operations on the infinity will lead to panic. If an operation result is too large or too small, the operation will panic instead of returning an infinity.

Implementations

The base of the representation. It’s exposed as an IBig constant.

Create a Repr instance representing value zero

Create a Repr instance representing value one

Create a Repr instance representing value negative one

Create a Repr instance representing the (positive) infinity

Create a Repr instance representing the negative infinity

Determine if the Repr represents zero

Examples
assert!(Repr::<2>::zero().is_zero());
assert!(!Repr::<10>::one().is_zero());

Determine if the Repr represents one

Examples
assert!(Repr::<2>::zero().is_zero());
assert!(!Repr::<10>::one().is_zero());

Determine if the Repr represents the (±)infinity

Examples
assert!(Repr::<2>::infinity().is_infinite());
assert!(Repr::<10>::neg_infinity().is_infinite());
assert!(!Repr::<10>::one().is_infinite());

Determine if the Repr represents a finite number

Examples
assert!(Repr::<2>::zero().is_finite());
assert!(Repr::<10>::one().is_finite());
assert!(!Repr::<16>::infinity().is_finite());

Get the sign of the number

Examples
assert_eq!(Repr::<2>::zero().sign(), Sign::Positive);
assert_eq!(Repr::<2>::neg_one().sign(), Sign::Negative);
assert_eq!(Repr::<10>::neg_infinity().sign(), Sign::Negative);

Get the number of digits (under base B) in the significand.

If the number is 0, then 0 is returned (instead of 1).

Examples
assert_eq!(Repr::<2>::zero().digits(), 0);
assert_eq!(Repr::<2>::one().digits(), 1);
assert_eq!(Repr::<10>::one().digits(), 1);

assert_eq!(Repr::<10>::new(100.into(), 0).digits(), 1); // 1e2
assert_eq!(Repr::<10>::new(101.into(), 0).digits(), 3);

Fast over-estimation of digits

Examples
assert_eq!(Repr::<2>::zero().digits_ub(), 0);
assert_eq!(Repr::<2>::one().digits_ub(), 1);
assert_eq!(Repr::<10>::one().digits_ub(), 1);
assert_eq!(Repr::<2>::new(31.into(), 0).digits_ub(), 5);
assert_eq!(Repr::<10>::new(99.into(), 0).digits_ub(), 2);

Fast under-estimation of digits

Examples
assert_eq!(Repr::<2>::zero().digits_lb(), 0);
assert_eq!(Repr::<2>::one().digits_lb(), 0);
assert_eq!(Repr::<10>::one().digits_lb(), 0);
assert_eq!(Repr::<10>::new(1001.into(), 0).digits_lb(), 3);

Create a Repr from the significand and exponent. This constructor will normalize the representation.

Examples
let a = Repr::<2>::new(400.into(), -2);
assert_eq!(a.significand(), &25);
assert_eq!(a.exponent(), 2);

let b = Repr::<10>::new(400.into(), -2);
assert_eq!(b.significand(), &4);
assert_eq!(b.exponent(), 0);

Get the significand of the representation

Get the exponent of the representation

Convert the float number into raw (signficand, exponent) parts

Examples
use dashu_int::IBig;

let a = Repr::<2>::new(400.into(), -2);
assert_eq!(a.into_parts(), (IBig::from(25), 2));

let b = Repr::<10>::new(400.into(), -2);
assert_eq!(b.into_parts(), (IBig::from(4), 0));

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Estimate the bounds of the binary logarithm. Read more
Estimate the value of the binary logarithm. It’s calculated as the average of log2_bounds by default. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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

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.