pub trait Real: Debug {
Show 15 methods
// Required methods
fn radix() -> usize;
fn sign(&self) -> Option<bool>;
fn exp(&self) -> Option<isize>;
fn e(&self) -> Option<isize>;
fn n(&self) -> Option<isize>;
fn c(&self) -> Option<Integer>;
fn m(&self) -> Option<Integer>;
fn prec(&self) -> Option<usize>;
fn is_nar(&self) -> bool;
fn is_finite(&self) -> bool;
fn is_infinite(&self) -> bool;
fn is_zero(&self) -> bool;
fn is_negative(&self) -> Option<bool>;
fn is_numerical(&self) -> bool;
// Provided method
fn split(&self, n: isize) -> (RFloat, RFloat) { ... }
}
Expand description
Universal trait for extended real numbers.
Computer number systems share certain characterstics.
Many can be represented by a finite-precision number in
scientific notation: (-1)^s * c * b^exp
where s
is the sign,
c
is the integer significand, b
is the radix, and exp
is
the exponent. Specifically, s
is either 0
or 1
, c
is
non-negative, and b
is positive. Number systems can usually be
split into two broad groups: floating-point or fixed-point,
where the “point” refers to the position of the least-significant digit
in c
when viewing the significand as an infinite sequence of digits
in either direction. Number systems may encode non-real numbers,
notably infinity or NaN.
See RoundingContext
for details on rounding.
Required Methods§
sourcefn sign(&self) -> Option<bool>
fn sign(&self) -> Option<bool>
The sign bit.
This is not always well-defined, so the result is an Option
.
This is distinct from is_negative
(e.g. -0.0
is not negative).
sourcefn exp(&self) -> Option<isize>
fn exp(&self) -> Option<isize>
The exponent of this number when viewed as (-1)^s * c * b^exp
where c
is an integer integer. Only well-defined for finite,
non-zero numbers.
sourcefn e(&self) -> Option<isize>
fn e(&self) -> Option<isize>
The exponent of this number when viewed as (-1)^s * f * b^e
where f
is a fraction between 1 and 2. This is the preferred
IEEE 754 interpretation of an exponent. Only well-defined for
finite, non-zero numbers.
sourcefn n(&self) -> Option<isize>
fn n(&self) -> Option<isize>
The “absolute digit”, the place below the least significant
digit of the mantissa. Always equal to self.exp() - 1
.
For integer formats, this is just -1. Only well-defined for
finite, non-zero numbers.
sourcefn c(&self) -> Option<Integer>
fn c(&self) -> Option<Integer>
The _unsigned“ integer significand of this number when viewed as
(-1)^s * c * b^exp
. Only well-defined for finite, non-zero
numbers. Only well-defined for finite, non-zero numbers.
sourcefn m(&self) -> Option<Integer>
fn m(&self) -> Option<Integer>
The signed integer significand of this number when viewed as
(-1)^s * c * b^exp
. Only well-defined for finite, non-zero
numbers. Only well-defined for finite, non-zero numbers.
sourcefn prec(&self) -> Option<usize>
fn prec(&self) -> Option<usize>
Precision of the significand.
This is just floor(logb(c))
where b
is the radix and c
is
the integer significand. Only well-defined for finite,
non-zero numbers.
sourcefn is_nar(&self) -> bool
fn is_nar(&self) -> bool
Returns true
if this number is not a real number.
Example: NaN or +/-Inf from the IEEE 754 standard.
sourcefn is_finite(&self) -> bool
fn is_finite(&self) -> bool
Returns true
if this number is finite.
For values that do not encode numbers, intervals, or even limiting
behavior, the result is false.
sourcefn is_infinite(&self) -> bool
fn is_infinite(&self) -> bool
Returns true
if this number if infinite.
For values that do not encode numbers, intervals, or even limiting
behavior, the result is false.
sourcefn is_negative(&self) -> Option<bool>
fn is_negative(&self) -> Option<bool>
Returns true
if this number is negative.
This is not always well-defined, so the result is an Option
.
This is not necessarily the same as the sign bit (the IEEE 754
standard differentiates between -0.0 and +0.0).
sourcefn is_numerical(&self) -> bool
fn is_numerical(&self) -> bool
Returns true
if this number represents a numerical value:
either a finite number, interval, or some limiting value.
Provided Methods§
sourcefn split(&self, n: isize) -> (RFloat, RFloat)
fn split(&self, n: isize) -> (RFloat, RFloat)
Splits this value at the n
th binary digit,
returning two RFloat
values.
The two values consist of:
- all significant digits above position
n
- all significant digits at or below position
n
The exact sum of the resulting values will be exactly num
,
so it “splits” num
.