pub struct f256 { /* private fields */ }Expand description
A 256-bit floating point type (specifically, the “binary256” type defined in IEEE 754-2008).
For details see above.
Implementations§
Source§impl f256
impl f256
Source§impl f256
impl f256
Source§impl f256
impl f256
Sourcepub fn log(&self, base: &Self) -> Self
pub fn log(&self, base: &Self) -> Self
Returns the logarithm of the number with respect to an arbitrary base.
The result might not be correctly rounded owing to implementation details; self.log2() can produce more accurate results for base 2, and self.log10() can produce more accurate results for base 10.
Source§impl f256
impl f256
Sourcepub const MANTISSA_DIGITS: u32 = SIGNIFICAND_BITS
pub const MANTISSA_DIGITS: u32 = SIGNIFICAND_BITS
Number of significant digits in base 2: 237.
Sourcepub const SIGNIFICANT_DIGITS: u32 = SIGNIFICAND_BITS
pub const SIGNIFICANT_DIGITS: u32 = SIGNIFICAND_BITS
Number of significant digits in base 2: 237.
Sourcepub const EPSILON: Self = EPSILON
pub const EPSILON: Self = EPSILON
The difference between 1.0 and the next larger representable number:
2⁻²³⁶ ≈ 9.055679 × 10⁻⁷².
Sourcepub const MIN_POSITIVE: Self = MIN_POSITIVE
pub const MIN_POSITIVE: Self = MIN_POSITIVE
Smallest positive normal f256 value: 2⁻²⁶²¹⁴² ≈ 2.4824 × 10⁻⁷⁸⁹¹³.
Sourcepub const MIN_GT_ZERO: Self = MIN_GT_ZERO
pub const MIN_GT_ZERO: Self = MIN_GT_ZERO
Smallest positive subnormal f256 value: 2⁻²⁶²³⁷⁸ ≈ 2.248 × 10⁻⁷⁸⁹⁸⁴.
Sourcepub const MIN_EXP: i32
pub const MIN_EXP: i32
One greater than the minimum possible normal power of 2 exponent: Eₘᵢₙ + 1 = -262141.
Sourcepub const MAX_10_EXP: i32 = 78913
pub const MAX_10_EXP: i32 = 78913
Maximum possible power of 10 exponent: ⌊(Eₘₐₓ + 1) × log₁₀(2)⌋.
Sourcepub const MIN_10_EXP: i32 = -78912
pub const MIN_10_EXP: i32 = -78912
Minimum possible normal power of 10 exponent: ⌊(Eₘᵢₙ + 1) × log₁₀(2)⌋.
Sourcepub const NAN: Self = NAN
pub const NAN: Self = NAN
Not a Number (NaN).
Note that IEEE-745 doesn’t define just a single NaN value; a plethora of bit patterns are considered to be NaN. Furthermore, the standard makes a difference between a “signaling” and a “quiet” NaN, and allows inspecting its “payload” (the unspecified bits in the bit pattern). This implementation does not make such a difference and uses exactly one bit pattern for NaN.
Sourcepub const NEG_INFINITY: Self = NEG_INFINITY
pub const NEG_INFINITY: Self = NEG_INFINITY
Negative infinity (−∞).
Sourcepub const fn is_infinite(self) -> bool
pub const fn is_infinite(self) -> bool
Returns true if this value is positive infinity or negative
infinity, and false otherwise.
Sourcepub const fn is_subnormal(self) -> bool
pub const fn is_subnormal(self) -> bool
Returns true if the number is subnormal.
Sourcepub const fn is_normal(self) -> bool
pub const fn is_normal(self) -> bool
Returns true if the number is neither zero, infinite, subnormal, or
NaN.
Sourcepub const fn classify(&self) -> FpCategory
pub const fn classify(&self) -> FpCategory
Returns the floating point category of the number. If only one property is going to be tested, it is generally faster to use the specific predicate instead.
Sourcepub const fn is_special(self) -> bool
pub const fn is_special(self) -> bool
Returns true if self is either not a number, infinite or equal to
zero.
Sourcepub const fn is_sign_positive(self) -> bool
pub const fn is_sign_positive(self) -> bool
Returns true if self has a positive sign, including +0.0,
positive infinity and NaN.
Sourcepub const fn is_sign_negative(self) -> bool
pub const fn is_sign_negative(self) -> bool
Returns true if self has a negative sign, including -0.0 and
negative infinity.
Sourcepub fn ulp(&self) -> Self
pub fn ulp(&self) -> Self
Returns the unit in the last place of self.
ULP denotes the magnitude of the last significand digit of self.
Sourcepub fn recip(self) -> Self
pub fn recip(self) -> Self
Returns the reciprocal (multiplicative inverse) of self.
§Examples
let f = f256::from(16);
let r = f256::from(0.0625);
assert_eq!(f.recip(), r);
assert_eq!(f256::INFINITY.recip(), f256::ZERO);
assert_eq!(f256::NEG_ZERO.recip(), f256::NEG_INFINITY);
assert!(f256::NAN.recip().is_nan());Sourcepub fn to_degrees(self) -> Self
pub fn to_degrees(self) -> Self
Converts radians to degrees.
Returns self * (180 / π)
Sourcepub fn to_radians(self) -> Self
pub fn to_radians(self) -> Self
Converts degrees to radians.
Returns self * (π / 180)
Sourcepub fn max(self, other: Self) -> Self
pub fn max(self, other: Self) -> Self
Returns the maximum of the two numbers, ignoring NaN.
If one of the arguments is NaN, then the other argument is returned. This follows the IEEE-754 2008 semantics for maxNum, except for handling of signaling NaNs; this function handles all NaNs the same way and avoids maxNum’s problems with associativity.
Sourcepub fn min(self, other: Self) -> Self
pub fn min(self, other: Self) -> Self
Returns the minimum of the two numbers, ignoring NaN.
If one of the arguments is NaN, then the other argument is returned. This follows the IEEE-754 2008 semantics for minNum, except for handling of signaling NaNs; this function handles all NaNs the same way and avoids minNum’s problems with associativity.
Sourcepub const fn to_bits(&self) -> (u128, u128)
pub const fn to_bits(&self) -> (u128, u128)
Raw transmutation to (u128, u128) ((self.bits.hi.0, self.bits.lo.0),
each in native endian order).
Sourcepub const fn from_bits(bits: (u128, u128)) -> Self
pub const fn from_bits(bits: (u128, u128)) -> Self
Raw transmutation from (u128, u128) ((self.bits.hi.0,
self.bits.lo.0), each in native endian order).
Sourcepub const fn to_be_bytes(self) -> [u8; 32]
pub const fn to_be_bytes(self) -> [u8; 32]
Return the memory representation of this floating point number as a byte array in big-endian (network) byte order.
Sourcepub const fn to_le_bytes(self) -> [u8; 32]
pub const fn to_le_bytes(self) -> [u8; 32]
Return the memory representation of this floating point number as a byte array in little-endian byte order.
Sourcepub const fn to_ne_bytes(self) -> [u8; 32]
pub const fn to_ne_bytes(self) -> [u8; 32]
Return the memory representation of this floating point number as a byte array in native byte order.
Sourcepub const fn from_be_bytes(bytes: [u8; 32]) -> Self
pub const fn from_be_bytes(bytes: [u8; 32]) -> Self
Create a floating point value from its representation as a byte array in big endian.
Sourcepub const fn from_le_bytes(bytes: [u8; 32]) -> Self
pub const fn from_le_bytes(bytes: [u8; 32]) -> Self
Create a floating point value from its representation as a byte array in little endian.
Sourcepub const fn from_ne_bytes(bytes: [u8; 32]) -> Self
pub const fn from_ne_bytes(bytes: [u8; 32]) -> Self
Create a floating point value from its representation as a byte array in native endian.
Sourcepub fn total_cmp(&self, other: &Self) -> Ordering
pub fn total_cmp(&self, other: &Self) -> Ordering
Return the ordering between self and other.
Unlike the standard partial comparison between floating point numbers,
this comparison always produces an ordering in accordance to
the totalOrder predicate as defined in the IEEE 754 (2008 revision)
floating point standard. The values are ordered in the following
sequence:
- negative NaN
- negative infinity
- negative numbers
- negative subnormal numbers
- negative zero
- positive zero
- positive subnormal numbers
- positive numbers
- positive infinity
- positive NaN.
The ordering established by this function does not always agree with
the PartialOrd and PartialEq implementations of f256.
For example, they consider negative and positive zero equal, while
total_cmp doesn’t.
Sourcepub fn clamp(self, min: Self, max: Self) -> Self
pub fn clamp(self, min: Self, max: Self) -> Self
Restrict a value to a certain interval unless it is NaN.
Returns max if self is greater than max, and min if self is
less than min. Otherwise this returns self.
Note that this function returns NaN if the initial value was NaN as well.
§Panics
Panics if min > max, min is NaN, or max is NaN.
§Examples
let min = f256::EPSILON;
let max = f256::TWO;
let f = f256::ONE;
assert_eq!(f.clamp(min, max), f);
assert_eq!((-f).clamp(min, max), min);
assert_eq!(f256::INFINITY.clamp(f256::MIN, f256::MAX), f256::MAX);
assert!(f256::NAN.clamp(f256::NEG_INFINITY, f256::INFINITY).is_nan());Sourcepub const fn abs(&self) -> Self
pub const fn abs(&self) -> Self
Computes the absolute value of self.
§Examples
let f = f256::from(138);
assert_eq!(f.abs(), f);
assert_eq!((-f).abs(), f);
assert_eq!(f256::MIN.abs(), f256::MAX);
assert_eq!(f256::NEG_INFINITY.abs(), f256::INFINITY);
assert!(f256::NAN.abs().is_nan());Sourcepub const fn copysign(self, other: Self) -> Self
pub const fn copysign(self, other: Self) -> Self
Returns a number composed of the magnitude of self and the sign of
other.
Equal to self if the sign of self and other are the same,
otherwise equal to -self.
If self is a NaN, then a NaN with the same payload as self and
the sign bit of other is returned.
If other is a NaN, then this operation will still carry over its
sign into the result. Note that IEEE 754 doesn’t assign any meaning to
the sign bit in case of a NaN, and as Rust doesn’t guarantee that the
bit pattern of NaNs are conserved over arithmetic operations, the
result of copysign with other being a NaN might produce an
unexpected or non-portable result.
Sourcepub const fn signum(self) -> Self
pub const fn signum(self) -> Self
Returns a number that represents the sign of self.
1.0if the number is positive,+0.0orINFINITY-1.0if the number is negative,-0.0orNEG_INFINITY- NaN if the number is NaN
Sourcepub fn trunc(&self) -> Self
pub fn trunc(&self) -> Self
Returns the integer part of self. This means that non-integer
numbers are always truncated towards zero.
§Examples
let f = f256::from(177);
let g = f256::from(177.503_f64);
let h = -g;
assert_eq!(f.trunc(), f);
assert_eq!(g.trunc(), f);
assert_eq!(h.trunc(), -f);Sourcepub fn fract(&self) -> Self
pub fn fract(&self) -> Self
Returns the fractional part of self.
§Examples
let f = f256::from(177);
let g = f256::from(177.503_f64);
let h = -g;
assert_eq!(f.fract(), f256::ZERO);
assert_eq!(g.fract(), g - f);
assert_eq!(h.fract(), f - g);Sourcepub fn ceil(&self) -> Self
pub fn ceil(&self) -> Self
Returns the smallest integer greater than or equal to self.
§Examples
let f = f256::from(28);
let g = f256::from(27.04_f64);
let h = -g;
assert_eq!(f.ceil(), f);
assert_eq!(g.ceil(), f);
assert_eq!(h.ceil(), f256::ONE - f);Sourcepub fn floor(&self) -> Self
pub fn floor(&self) -> Self
Returns the largest integer less than or equal to self.
§Examples
let f = f256::from(57);
let g = f256::from(57.009_f64);
let h = -g;
assert_eq!(f.floor(), f);
assert_eq!(g.floor(), f);
assert_eq!(h.floor(), -f - f256::ONE);Sourcepub fn round(&self) -> Self
pub fn round(&self) -> Self
Returns the nearest integer to self. Rounds half-way cases away from
zero.
§Examples
let f = f256::from(27);
let g = f256::from(26.704_f64);
let h = f256::from(26.5_f64);
assert_eq!(f.round(), f);
assert_eq!(g.round(), f);
assert_eq!(h.round(), f);Sourcepub fn round_tie_even(&self) -> Self
pub fn round_tie_even(&self) -> Self
Returns the nearest integer to self. Rounds half-way cases to the
nearest even.
§Examples
let f = f256::from(28);
let g = f256::from(27.704_f64);
let h = f256::from(27.5_f64);
let h = f256::from(28.5_f64);
assert_eq!(f.round_tie_even(), f);
assert_eq!(g.round_tie_even(), f);
assert_eq!(h.round_tie_even(), f);Sourcepub fn midpoint(self, other: Self) -> Self
pub fn midpoint(self, other: Self) -> Self
Calculates the midpoint (average) between self and rhs.
This returns NaN when either argument is NaN or if a combination of +inf and -inf is provided as arguments.
Sourcepub fn hypot(self, other: Self) -> Self
pub fn hypot(self, other: Self) -> Self
Compute the distance between the origin and a point (x, y) on the
Euclidean plane. Equivalently, compute the length of the hypotenuse of
a right-angle triangle with other sides having length x.abs() and
y.abs().
Sourcepub fn next_up(self) -> Self
pub fn next_up(self) -> Self
Returns the least number greater than self.
Maps the input value as follows:
- Self::NAN => Self::NAN
- Self::NEG_INFINITY ==> Self::MIN
- -Self::MIN_GT_ZERO => Self::NEG_ZERO
- Self::ZERO or Self::NEG_ZERO => Self::MIN_GT_ZERO
- Self::MAX or Self::INFINITY => Self::INFINITY
- otherwise => unique least value greater than
self
The identity x.next_up() == -(-x).next_down() holds for all
non-NaN x. When x is finite x == x.next_down().next_up() also
holds.
Sourcepub fn next_down(self) -> Self
pub fn next_down(self) -> Self
Returns the greatest number less than self.
Maps the input value as follows:
- Self::NAN => Self::NAN
- Self::INFINITY ==> Self::MAX
- Self::MIN_GT_ZERO => Self::ZERO
- Self::ZERO or Self::NEG_ZERO => -Self::MIN_GT_ZERO
- Self::MIN or Self::NEG_INFINITY => Self::NEG_INFINITY
- otherwise => unique greatest value less than
self
The identity x.next_down() == -(-x).next_up() holds for all
non-NaN x. When x is finite x == x.next_down().next_up() also
holds.
Sourcepub fn mul_add(self, f: Self, a: Self) -> Self
pub fn mul_add(self, f: Self, a: Self) -> Self
Fused multiply-add.
Computes (self * f) + a with only one rounding error, yielding a
more accurate result than a non-fused multiply-add.
Sourcepub fn sum_of_squares(self, other: Self) -> Self
pub fn sum_of_squares(self, other: Self) -> Self
Fused sum of squares.
Computes (self * self) + (other * other) with only one rounding
error, yielding a more accurate result than a non-fused sum of
squares.
Sourcepub fn square_add(self, a: Self) -> Self
pub fn square_add(self, a: Self) -> Self
Fused square-add.
Computes (self * self) + a with only one rounding error, yielding a
more accurate result than a non-fused square-add.
Sourcepub fn div_euclid(self, rhs: Self) -> Self
pub fn div_euclid(self, rhs: Self) -> Self
Calculates Euclidean division, the matching method for rem_euclid.
This computes the integer n such that self = n * rhs + self.rem_euclid(rhs). In other words, the result is self / rhs rounded to the integer n such that self >= n * rhs.
Sourcepub fn rem_euclid(self, rhs: Self) -> Self
pub fn rem_euclid(self, rhs: Self) -> Self
Calculates the least nonnegative remainder of self (mod rhs).
In particular, the return value r satisfies 0.0 <= r < rhs.abs() in most cases. However, due to a floating point round-off error it can result in r == rhs.abs(), violating the mathematical definition, if self is much smaller than rhs.abs() in magnitude and self < 0.0. This result is not an element of the function’s codomain, but it is the closest floating point number in the real numbers and thus fulfills the property self == self.div_euclid(rhs) * rhs + self.rem_euclid(rhs) approximately.
Sourcepub fn rn2sum(self, rhs: Self) -> (Self, Self)
pub fn rn2sum(self, rhs: Self) -> (Self, Self)
Computes the floating-point sum s := a ⊕ b and the floating-point error t := a + b − ( a ⊕ b ) so that s + t = a + b, where ⊕ denotes the addition rounded to nearest.
Note: When a ⊕ b is infinite or not a number, NaN is returned as t.
Sourcepub fn frn2sum(self, rhs: Self) -> (Self, Self)
pub fn frn2sum(self, rhs: Self) -> (Self, Self)
Computes the floating-point sum s := a ⊕ b and the floating-point error t := a + b − ( a ⊕ b ) so that s + t = a + b, where ⊕ denotes the addition rounded to nearest.
Note: When a ⊕ b is infinite or not a number, NaN is returned as t.
Pre-condition: |a| >= |b|
Sourcepub fn rn2mul(self, rhs: Self) -> (Self, Self)
pub fn rn2mul(self, rhs: Self) -> (Self, Self)
Computes the floating-point product p := a ⨂ b and the floating-point error t := a × b − ( a ⊗ b ) so that p + t = a × b, where ⨂ denotes the multiplication rounded to nearest.
Note: When a ⊕ b is infinite or not a number, NaN is returned as t.
Pre-condition: |a ⨂ b| > 0 => exp(a) + exp(b) >= Eₘᵢₙ + 236
Trait Implementations§
Source§impl<T> AddAssign<T> for f256
impl<T> AddAssign<T> for f256
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl<T> DivAssign<T> for f256
impl<T> DivAssign<T> for f256
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<T> MulAssign<T> for f256
impl<T> MulAssign<T> for f256
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl PartialOrd for f256
impl PartialOrd for f256
Source§impl<T> RemAssign<T> for f256
impl<T> RemAssign<T> for f256
Source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%= operation. Read moreSource§impl<T> SubAssign<T> for f256
impl<T> SubAssign<T> for f256
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more