pub trait FloatMath: FloatMathWithPolicy {
// Provided methods
fn ldexp(self, exp: Self::SignedBits) -> Self { ... }
fn frexp(self) -> (Self, Self::SignedBits) { ... }
fn flush_denormals(self) -> Self { ... }
}Expand description
Float Math functions for floating-point vectors using the default policy.
Float-specific mathematical functions like ldexp and frexp.
This trait requires FloatVectorWithBits via the bounds on FloatMathWithPolicy.
This trait provides the same set of mathematical operations as FloatMathWithPolicy,
but uses the DefaultPolicy for all operations. This allows for easier usage
when specific policy customization is not required.
Implementors of FloatMathWithPolicy will automatically implement this trait as well.
All methods here have an associated method in FloatMathWithPolicy with a _p suffix
that accepts a policy parameter as the first generic argument.
Provided Methods§
Sourcefn ldexp(self, exp: Self::SignedBits) -> Self
fn ldexp(self, exp: Self::SignedBits) -> Self
Computes self * 2^exp efficiently.
The default policy handles the full domain: overflow gives a signed
infinity, underflow a signed zero (or a subnormal under a
Preserve denormal policy), and infinities/NaNs pass through. That
costs a handful of compares and selects around the exponent
arithmetic.
A caller whose exponent is known to stay in range (anything fed by
frexp, for instance) can drop all of it with
ldexp_p::<CheckOverflow<P, false>>(exp), leaving an add, a shift
and an or. Out-of-domain inputs are then garbage in, garbage out.
Sourcefn frexp(self) -> (Self, Self::SignedBits)
fn frexp(self) -> (Self, Self::SignedBits)
Decomposes self into its normalized fraction and an integral power of two.
self == frac * 2^exp with 0.5 <= |frac| < 1; +-0 gives
(+-0, 0), and infinities and NaNs pass through unchanged.
Unless the DenormalBehavior is set to Ignore,
denormal/subnormal values are properly handled regardless, not flushed. Mixed
workloads of normal and denormal values will be slower than all-similar workloads
due to branch prediction misprediction. This was the fastest approach overall.
Sourcefn flush_denormals(self) -> Self
fn flush_denormals(self) -> Self
Removes denormal/subnormal values, flushing them to zero.
If the precision policy is less than Best,
this will NOT preserve -0.0. However, at higher precision policies the
negative zero will be correctly preserved.
The crate feature preserve_denormals will disable this for default policies,
which may be useful when targeting hardware or applications where the processor
will handle denormals automatically.
See DenormalBehavior for more options for how to control
this function, as it is used extensively internally.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".