Trait lav::Real [−][src]
pub trait Real where
Self: Clone + Copy + Default,
Self: PartialEq + PartialOrd,
Self: From<u8> + From<i8>,
Self: From<u16> + From<i16>,
Self: FromStr,
Self: Product<Self> + Sum<Self>,
for<'a> Self: Product<&'a Self> + Sum<&'a Self>,
Self: FloatToInt<usize> + FloatToInt<isize>,
Self: FloatToInt<u128> + FloatToInt<i128>,
Self: FloatToInt<u64> + FloatToInt<i64>,
Self: FloatToInt<u32> + FloatToInt<i32>,
Self: FloatToInt<u16> + FloatToInt<i16>,
Self: FloatToInt<u8> + FloatToInt<i8>,
Self: Debug + LowerExp + UpperExp + Display,
Self: Add<Output = Self> + AddAssign,
Self: Sub<Output = Self> + SubAssign,
Self: Mul<Output = Self> + MulAssign,
Self: Div<Output = Self> + DivAssign,
Self: Rem<Output = Self> + RemAssign,
for<'a> Self: Add<&'a Self, Output = Self> + AddAssign<&'a Self>,
for<'a> Self: Sub<&'a Self, Output = Self> + SubAssign<&'a Self>,
for<'a> Self: Mul<&'a Self, Output = Self> + MulAssign<&'a Self>,
for<'a> Self: Div<&'a Self, Output = Self> + DivAssign<&'a Self>,
for<'a> Self: Rem<&'a Self, Output = Self> + RemAssign<&'a Self>,
Self: Neg<Output = Self>,
Self: SimdElement, {
type Bits: Bits;
type Simd: SimdReal<Self, LANES>;
Show 37 associated constants and 57 methods
const ZERO: Self;
const ONE: Self;
const TWO: Self;
const PI: Self;
const TAU: Self;
const SQRT_2: Self;
const FRAC_1_2: Self;
const FRAC_1_3: Self;
const FRAC_1_4: Self;
const FRAC_1_6: Self;
const FRAC_1_8: Self;
const FRAC_PI_2: Self;
const FRAC_PI_3: Self;
const FRAC_PI_4: Self;
const FRAC_PI_6: Self;
const FRAC_PI_8: Self;
const FRAC_1_PI: Self;
const FRAC_1_TAU: Self;
const FRAC_1_SQRT_2: Self;
const FRAC_2_PI: Self;
const FRAC_2_SQRT_PI: Self;
const EPSILON: Self;
const SQRT_EPSILON: Self;
const CBRT_EPSILON: Self;
const RADIX: u32;
const MANTISSA_DIGITS: u32;
const DIGITS: u32;
const MIN: Self;
const MIN_POSITIVE: Self;
const MAX: Self;
const MIN_EXP: i32;
const MAX_EXP: i32;
const MIN_10_EXP: i32;
const MAX_10_EXP: i32;
const NAN: Self;
const INFINITY: Self;
const NEG_INFINITY: Self;
fn from_bits(bits: Self::Bits) -> Self;
fn to_bits(self) -> Self::Bits;
fn is_sign_positive(self) -> bool;
fn is_sign_negative(self) -> bool;
fn is_nan(self) -> bool;
fn is_infinite(self) -> bool;
fn is_finite(self) -> bool;
fn is_subnormal(self) -> bool;
fn is_normal(self) -> bool;
fn classify(self) -> FpCategory;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round(self) -> Self;
fn trunc(self) -> Self;
fn fract(self) -> Self;
fn abs(self) -> Self;
fn signum(self) -> Self;
fn copysign(self, sign: Self) -> Self;
fn min(self, other: Self) -> Self;
fn max(self, other: Self) -> Self;
fn clamp(self, min: Self, max: Self) -> Self;
fn recip(self) -> Self;
fn to_radians(self) -> Self;
fn to_degrees(self) -> Self;
fn mul_add(self, a: Self, b: Self) -> Self;
fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
fn powf(self, n: Self) -> Self;
fn exp(self) -> Self;
fn exp_m1(self) -> Self;
fn exp2(self) -> Self;
fn ln(self) -> Self;
fn ln_1p(self) -> Self;
fn log(self, base: Self) -> Self;
fn log2(self) -> Self;
fn log10(self) -> Self;
fn sqrt(self) -> Self;
fn cbrt(self) -> Self;
fn hypot(self, other: Self) -> Self;
fn sin(self) -> Self;
fn sinh(self) -> Self;
fn cos(self) -> Self;
fn cosh(self) -> Self;
fn sin_cos(self) -> (Self, Self);
fn tan(self) -> Self;
fn asin(self) -> Self;
fn asinh(self) -> Self;
fn acos(self) -> Self;
fn acosh(self) -> Self;
fn atan(self) -> Self;
fn atanh(self) -> Self;
fn atan2(self, other: Self) -> Self;
fn lerp(self, start: Self, end: Self) -> Self;
fn total_cmp(&self, other: &Self) -> Ordering;
fn approx_eq(self, other: Self, epsilon: Self, ulp: Self::Bits) -> bool { ... }
fn approx_ne(self, other: Self, epsilon: Self, ulp: Self::Bits) -> bool { ... }
fn splat<const LANES: usize>(self) -> Self::Simd
where
LaneCount<LANES>: SupportedLaneCount,
{ ... }
}Expand description
Associated Types
Associated Constants
const FRAC_1_TAU: Self
const FRAC_1_TAU: Self
$\frac{1}{\tau}$
const FRAC_1_SQRT_2: Self
const FRAC_1_SQRT_2: Self
$\frac{1}{\sqrt{2}}$
const FRAC_2_SQRT_PI: Self
const FRAC_2_SQRT_PI: Self
$\frac{2}{\sqrt{\pi}}$
Machine epsilon $\epsilon$ of floating-point type.
const SQRT_EPSILON: Self
const SQRT_EPSILON: Self
$\sqrt{\epsilon}$
const CBRT_EPSILON: Self
const CBRT_EPSILON: Self
$\sqrt[3]{\epsilon}$
const MANTISSA_DIGITS: u32
const MANTISSA_DIGITS: u32
Number of significant digits in base $2$.
const MIN_POSITIVE: Self
const MIN_POSITIVE: Self
Smallest positive normal floating-point type value.
const MIN_10_EXP: i32
const MIN_10_EXP: i32
Minimum possible normal power of $10$ exponent.
const MAX_10_EXP: i32
const MAX_10_EXP: i32
Maximum possible power of $10$ exponent.
const NEG_INFINITY: Self
const NEG_INFINITY: Self
Negative infinity $-\infty$.
Required methods
Raw transmutation from u64.
This is currently identical to transmute::<u64, f64>(v) on all
platforms. It turns out this is incredibly portable, for two reasons:
- Floats and Ints have the same endianness on all supported platforms.
- IEEE-754 very precisely specifies the bit layout of floats.
However there is one caveat: prior to the 2008 version of IEEE-754, how to interpret the NaN signaling bit wasn’t actually specified. Most platforms (notably x86 and ARM) picked the interpretation that was ultimately standardized in 2008, but some didn’t (notably MIPS). As a result, all signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.
Rather than trying to preserve signaling-ness cross-platform, this implementation favors preserving the exact bits. This means that any payloads encoded in NaNs will be preserved even if the result of this method is sent over the network from an x86 machine to a MIPS one.
If the results of this method are only manipulated by the same architecture that produced them, then there is no portability concern.
If the input isn’t NaN, then there is no portability concern.
If you don’t care about signaling-ness (very likely), then there is no portability concern.
Note that this function is distinct from as casting, which attempts to preserve the
numeric value, and not the bitwise value.
Raw transmutation to u64.
This is currently identical to transmute::<f64, u64>(self) on all
platforms.
See from_bits for some discussion of the portability of this operation
(there are almost no issues).
Note that this function is distinct from as casting, which attempts to preserve the
numeric value, and not the bitwise value.
fn is_sign_positive(self) -> bool
fn is_sign_positive(self) -> bool
Returns true for each lane if it has a positive sign, including +0.0, NaNs with positive
sign bit and positive infinity.
fn is_sign_negative(self) -> bool
fn is_sign_negative(self) -> bool
Returns true for each lane if it has a negative sign, including -0.0, NaNs with negative
sign bit and negative infinity.
fn is_infinite(self) -> bool
fn is_infinite(self) -> bool
Returns true for each lane if its value is positive infinity or negative infinity.
fn is_subnormal(self) -> bool
fn is_subnormal(self) -> bool
Returns true for each lane if its value is subnormal.
Returns true for each lane if its value is neither neither zero, infinite, subnormal, or
NaN.
fn classify(self) -> FpCategory
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.
Returns the nearest integer to a number. Round half-way cases away from 0.0.
Computes the absolute value of self.
Returns Self::NAN if the number is NaN.
Returns a number that represents the sign of self.
- Returns
1.0if the number is positive,+0.0orSelf::INFINITY. - Returns
-1.0if the number is negative,-0.0orSelf::NEG_INFINITY. - Returns
Self::NANif the number is NaN.
Returns a number composed of the magnitude of self and the sign of sign.
Equal to self if the sign of self and sign are the same, otherwise equal to -self.
If self is NaN, then NaN with the sign of sign is returned.
Returns the minimum of each lane.
If one of the values is NaN, then the other value is returned.
Returns the maximum of each lane.
If one of the values is NaN, then the other value is returned.
Restrict each lane to a certain interval unless it is NaN.
For each lane in self, returns the corresponding lane in max if the lane is greater than
max, and the corresponding lane in min if the lane is less than min. Otherwise,
returns the lane in self.
fn to_radians(self) -> Self
fn to_radians(self) -> Self
Converts degrees to radians.
fn to_degrees(self) -> Self
fn to_degrees(self) -> Self
Converts radians to degrees.
Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more
accurate result than an unfused multiply-add.
Using mul_add may be more performant than an unfused multiply-add if the target
architecture has a dedicated fma CPU instruction. However, this is not always true, and
will be heavily dependant on designing algorithms with specific target hardware in mind.
fn div_euclid(self, rhs: Self) -> Self
fn div_euclid(self, rhs: Self) -> Self
Calculates Euclidean division, the matching method for Self::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.
fn rem_euclid(self, rhs: Self) -> Self
fn rem_euclid(self, rhs: Self) -> Self
Calculates the least non-negative 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) approximatively.
Returns $e^x - 1$ in a way that is accurate even if the number is close to zero.
Returns the natural logarithm of the number plus one more accurately than if the operations were performed separately.
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$, andSelf::log10()can produce more accurate results for base $10$.
Returns the square root of a number.
Returns NaN if self is a negative number.
Calculates the length of the hypotenuse of a right-angle triangle given legs of length
self and other.
Simultaneously computes the sine and cosine of self.
Returns (self.sin(), self.cos()).
Computes the arcsine of a number.
Return value is in radians in the range $[-{\pi \over 2}, {\pi \over 2}]$ or NaN if the number is outside the range $[-1, 1]$.
Computes the arccosine of a number.
Return value is in radians in the range $[0, \pi]$ or NaN if the number is outside the range $[-1, 1]$.
Computes the arctangent of a number.
Return value is in radians in the range $[-{\pi \over 2}, {\pi \over 2}]$.
Computes the four quadrant arctangent of self as $y$ and other as $x$ in radians.
$$ \arctan(y, x) = \begin{cases} 0 & \text{if } x = 0 \wedge y = 0 \\ \arctan({y \over x}) \in [-{\pi \over 2}, {\pi \over 2}] & \text{if } x \ge 0 \\ \arctan({y \over x}) + \pi \in ({\pi \over 2}, \pi] & \text{if } y \ge 0 \\ \arctan({y \over x}) - \pi \in (-{\pi \over 2}, -{\pi \over 2}) & \text{if } y \lt 0 \end{cases} $$
Linear interpolation between start and end.
This enables linear interpolation between start and end, where start is represented by
self == 0.0 and end is represented by self == 1.0. This is the basis of all
“transition”, “easing”, or “step” functions; if you change self from 0.0 to 1.0
at a given rate, the result will change from start to end at a similar rate.
Values below 0.0 or above 1.0 are allowed, allowing you to extrapolate values outside the
range from start to end. This also is useful for transition functions which might
move slightly past the end or start for a desired effect. Mathematically, the values
returned are equivalent to start + self * (end - start), although we make a few specific
guarantees that are useful specifically to linear interpolation.
These guarantees are:
- If
startandendare finite, the value at 0.0 is alwaysstartand the value at 1.0 is alwaysend. (exactness) - If
startandendare finite, the values will always move in the direction fromstarttoend(monotonicity) - If
selfis finite andstart == end, the value at any point will always bestart == end. (consistency)
Returns an ordering between self and other values.
Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in IEEE 754 (2008 revision) floating point standard. The values are ordered in following order:
- Negative quiet NaN
- Negative signaling NaN
- Negative infinity
- Negative numbers
- Negative subnormal numbers
- Negative zero
- Positive zero
- Positive subnormal numbers
- Positive numbers
- Positive infinity
- Positive signaling NaN
- Positive quiet NaN
Note that this function does not always agree with the PartialOrd and PartialEq
implementations of floating-point type. In particular, they regard negative and positive
zero as equal, while Self::total_cmp() does not.
Provided methods
Tests for approximate equality wrt epsilon or ulp, “or” in the sense of ||.
Tests for approximate inequality wrt epsilon and ulp, “and” in the sense of &&.
