pub trait Realwhere
for<'a, 'a, 'a, 'a, 'a, 'a> Self: Send + Sync + Clone + Copy + Default + ApproxEq<Self, Self> + PartialEq + PartialOrd + From<u8> + From<i8> + From<u16> + From<i16> + FromStr<Err = ParseFloatError> + Product<Self> + Sum<Self> + Product<&'a Self> + Sum<&'a Self> + FloatToInt<usize> + FloatToInt<isize> + FloatToInt<u128> + FloatToInt<i128> + FloatToInt<u64> + FloatToInt<i64> + FloatToInt<u32> + FloatToInt<i32> + FloatToInt<u16> + FloatToInt<i16> + FloatToInt<u8> + FloatToInt<i8> + Debug + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign + Rem<Output = Self> + RemAssign + Add<&'a Self, Output = Self> + AddAssign<&'a Self> + Sub<&'a Self, Output = Self> + SubAssign<&'a Self> + Mul<&'a Self, Output = Self> + MulAssign<&'a Self> + Div<&'a Self, Output = Self> + DivAssign<&'a Self> + Rem<&'a Self, Output = Self> + RemAssign<&'a Self> + Neg<Output = Self> + SimdElement,{
type Bits: Bits;
type Simd<const N: usize>: SimdReal<Self, N>
where LaneCount<N>: SupportedLaneCount;
Show 38 associated constants and 56 methods
const NATIVE_LANE_COUNT: usize;
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;
// Required methods
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 total_cmp(&self, other: &Self) -> Ordering;
// Provided methods
fn splat<const N: usize>(self) -> Self::Simd<N>
where LaneCount<N>: SupportedLaneCount { ... }
fn as_simd<const N: usize>(
slice: &[Self]
) -> (&[Self], &[Self::Simd<N>], &[Self])
where LaneCount<N>: SupportedLaneCount { ... }
fn as_simd_mut<const N: usize>(
slice: &mut [Self]
) -> (&mut [Self], &mut [Self::Simd<N>], &mut [Self])
where LaneCount<N>: SupportedLaneCount { ... }
}
Expand description
Required Associated Types§
Required Associated Constants§
sourceconst NATIVE_LANE_COUNT: usize
Available on crate feature target-features
only.
const NATIVE_LANE_COUNT: usize
target-features
only.Native lane count of current build target or 1
if unknown.
sourceconst FRAC_1_TAU: Self
const FRAC_1_TAU: Self
$\frac{1}{\tau}$
sourceconst FRAC_1_SQRT_2: Self
const FRAC_1_SQRT_2: Self
$\frac{1}{\sqrt{2}}$
sourceconst FRAC_2_SQRT_PI: Self
const FRAC_2_SQRT_PI: Self
$\frac{2}{\sqrt{\pi}}$
sourceconst EPSILON: Self
const EPSILON: Self
Machine epsilon $\epsilon$ of floating-point type.
sourceconst SQRT_EPSILON: Self
const SQRT_EPSILON: Self
$\sqrt{\epsilon}$
sourceconst CBRT_EPSILON: Self
const CBRT_EPSILON: Self
$\sqrt[3]{\epsilon}$
sourceconst MANTISSA_DIGITS: u32
const MANTISSA_DIGITS: u32
Number of significant digits in base $2$.
sourceconst MIN_POSITIVE: Self
const MIN_POSITIVE: Self
Smallest positive normal floating-point type value.
sourceconst MIN_10_EXP: i32
const MIN_10_EXP: i32
Minimum possible normal power of $10$ exponent.
sourceconst MAX_10_EXP: i32
const MAX_10_EXP: i32
Maximum possible power of $10$ exponent.
sourceconst NEG_INFINITY: Self
const NEG_INFINITY: Self
Negative infinity $-\infty$.
Required Methods§
sourcefn from_bits(bits: Self::Bits) -> Self
fn from_bits(bits: Self::Bits) -> Self
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.
sourcefn to_bits(self) -> Self::Bits
fn to_bits(self) -> Self::Bits
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.
sourcefn 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.
sourcefn 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.
sourcefn is_infinite(self) -> bool
fn is_infinite(self) -> bool
Returns true
for each lane if its value is positive infinity or negative infinity.
sourcefn is_finite(self) -> bool
fn is_finite(self) -> bool
Returns true
for each lane if its value is neither infinite nor NaN.
sourcefn is_subnormal(self) -> bool
fn is_subnormal(self) -> bool
Returns true
for each lane if its value is subnormal.
sourcefn is_normal(self) -> bool
fn is_normal(self) -> bool
Returns true
for each lane if its value is neither neither zero, infinite, subnormal, or
NaN.
sourcefn 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.
sourcefn round(self) -> Self
fn round(self) -> Self
Returns the nearest integer to a number. Round half-way cases away from 0.0
.
sourcefn abs(self) -> Self
fn abs(self) -> Self
Computes the absolute value of self
.
Returns Self::NAN
if the number is NaN.
sourcefn signum(self) -> Self
fn signum(self) -> Self
Returns a number that represents the sign of self
.
- Returns
1.0
if the number is positive,+0.0
orSelf::INFINITY
. - Returns
-1.0
if the number is negative,-0.0
orSelf::NEG_INFINITY
. - Returns
Self::NAN
if the number is NaN.
sourcefn copysign(self, sign: Self) -> Self
fn copysign(self, sign: Self) -> Self
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.
sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Returns the minimum of each lane.
If one of the values is NaN, then the other value is returned.
sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Returns the maximum of each lane.
If one of the values is NaN, then the other value is returned.
sourcefn clamp(self, min: Self, max: Self) -> Self
fn clamp(self, min: Self, max: Self) -> Self
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
.
sourcefn to_radians(self) -> Self
fn to_radians(self) -> Self
Converts degrees to radians.
sourcefn to_degrees(self) -> Self
fn to_degrees(self) -> Self
Converts radians to degrees.
sourcefn mul_add(self, a: Self, b: Self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
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.
sourcefn 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
.
sourcefn 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.
sourcefn exp_m1(self) -> Self
fn exp_m1(self) -> Self
Returns $e^x - 1$ in a way that is accurate even if the number is close to zero.
sourcefn ln_1p(self) -> Self
fn ln_1p(self) -> Self
Returns the natural logarithm of the number plus one more accurately than if the operations were performed separately.
sourcefn log(self, base: Self) -> Self
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$, andSelf::log10()
can produce more accurate results for base $10$.
sourcefn sqrt(self) -> Self
fn sqrt(self) -> Self
Returns the square root of a number.
Returns NaN if self
is a negative number.
sourcefn hypot(self, other: Self) -> Self
fn hypot(self, other: Self) -> Self
Calculates the length of the hypotenuse of a right-angle triangle given legs of length
self
and other
.
sourcefn sin_cos(self) -> (Self, Self)
fn sin_cos(self) -> (Self, Self)
Simultaneously computes the sine and cosine of self
.
Returns (self.sin(), self.cos())
.
sourcefn asin(self) -> Self
fn asin(self) -> Self
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]$.
sourcefn acos(self) -> Self
fn acos(self) -> Self
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]$.
sourcefn atan(self) -> Self
fn atan(self) -> Self
Computes the arctangent of a number.
Return value is in radians in the range $[-{\pi \over 2}, {\pi \over 2}]$.
sourcefn atan2(self, other: Self) -> Self
fn atan2(self, other: Self) -> Self
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} $$
sourcefn total_cmp(&self, other: &Self) -> Ordering
fn total_cmp(&self, other: &Self) -> Ordering
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§
sourcefn splat<const N: usize>(self) -> Self::Simd<N>where
LaneCount<N>: SupportedLaneCount,
fn splat<const N: usize>(self) -> Self::Simd<N>where
LaneCount<N>: SupportedLaneCount,
Constructs a SIMD vector by setting all lanes to the given value.
sourcefn as_simd<const N: usize>(
slice: &[Self]
) -> (&[Self], &[Self::Simd<N>], &[Self])where
LaneCount<N>: SupportedLaneCount,
fn as_simd<const N: usize>(
slice: &[Self]
) -> (&[Self], &[Self::Simd<N>], &[Self])where
LaneCount<N>: SupportedLaneCount,
Split a slice into a prefix, a middle of aligned SIMD vectors, and a suffix.
You’re only assured thatcself.len() == prefix.len() + middle.len() * N + suffix.len()
.
Notably, all of the following are possible:
prefix.len() >= N
,middle.is_empty()
despiteself.len() >= 3 * N
,suffix.len() >= N
.
That said, this is a safe method, so if you’re only writing safe code, then this can at most cause incorrect logic, not unsoundness.
§Panics
Panic if the size of the SIMD vector is different from N
times that of the scalar.
sourcefn as_simd_mut<const N: usize>(
slice: &mut [Self]
) -> (&mut [Self], &mut [Self::Simd<N>], &mut [Self])where
LaneCount<N>: SupportedLaneCount,
fn as_simd_mut<const N: usize>(
slice: &mut [Self]
) -> (&mut [Self], &mut [Self::Simd<N>], &mut [Self])where
LaneCount<N>: SupportedLaneCount,
Split a mutable slice into a mutable prefix, a middle of aligned SIMD vectors, and a mutable suffix.
You’re only assured that self.len() == prefix.len() + middle.len() * N + suffix.len()
.
Notably, all of the following are possible:
prefix.len() >= N
,middle.is_empty()
despiteself.len() >= 3 * N
,suffix.len() >= N
.
That said, this is a safe method, so if you’re only writing safe code, then this can at most cause incorrect logic, not unsoundness.
This is the mutable version of Self::as_simd
.
§Panics
Panic if the size of the SIMD vector is different from N
times that of the scalar.
Object Safety§
Implementations on Foreign Types§
source§impl Real for f32
impl Real for f32
type Bits = u32
type Simd<const N: usize> = Simd<f32, N> where LaneCount<N>: SupportedLaneCount
source§const NATIVE_LANE_COUNT: usize = 4usize
const NATIVE_LANE_COUNT: usize = 4usize
target-features
only.const ZERO: Self = 0f32
const ONE: Self = 1f32
const TWO: Self = 2f32
const PI: Self = 3.14159274f32
const TAU: Self = 6.28318548f32
const SQRT_2: Self = 1.41421354f32
const FRAC_1_2: Self = 0.5f32
const FRAC_1_3: Self = 0.333333343f32
const FRAC_1_4: Self = 0.25f32
const FRAC_1_6: Self = 0.166666672f32
const FRAC_1_8: Self = 0.125f32
const FRAC_PI_2: Self = 1.57079637f32
const FRAC_PI_3: Self = 1.04719758f32
const FRAC_PI_4: Self = 0.785398185f32
const FRAC_PI_6: Self = 0.52359879f32
const FRAC_PI_8: Self = 0.392699093f32
const FRAC_1_PI: Self = 0.318309873f32
const FRAC_1_TAU: Self = 0.159154937f32
const FRAC_1_SQRT_2: Self = 0.707106769f32
const FRAC_2_PI: Self = 0.636619746f32
const FRAC_2_SQRT_PI: Self = 1.12837923f32
const EPSILON: Self = 1.1920929E-7f32
const SQRT_EPSILON: Self = 3.45266977E-4f32
const CBRT_EPSILON: Self = 0.00492156669f32
const RADIX: u32 = 2u32
const MANTISSA_DIGITS: u32 = 24u32
const DIGITS: u32 = 6u32
const MIN: Self = -3.40282347E+38f32
const MIN_POSITIVE: Self = 1.17549435E-38f32
const MAX: Self = 3.40282347E+38f32
const MIN_EXP: i32 = -125i32
const MAX_EXP: i32 = 128i32
const MIN_10_EXP: i32 = -37i32
const MAX_10_EXP: i32 = 38i32
const NAN: Self = NaN_f32
const INFINITY: Self = +Inf_f32
const NEG_INFINITY: Self = -Inf_f32
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 total_cmp(&self, other: &Self) -> Ordering
source§impl Real for f64
impl Real for f64
type Bits = u64
type Simd<const N: usize> = Simd<f64, N> where LaneCount<N>: SupportedLaneCount
source§const NATIVE_LANE_COUNT: usize = 2usize
const NATIVE_LANE_COUNT: usize = 2usize
target-features
only.