pub trait SimdFloat<S: Simd>:
SimdBase<S, Element: SimdFloatElement>
+ Seal
+ Neg<Output = Self>
+ Div<Output = Self>
+ DivAssign
+ Div<Self::Element, Output = Self>
+ DivAssign<Self::Element> {
Show 14 methods
// Required methods
fn sqrt(self) -> Self;
fn approximate_recip(self) -> Self;
fn copysign(self, rhs: impl SimdInto<Self, S>) -> Self;
fn mul_add(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self;
fn mul_add_precise(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self;
fn mul_sub(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self;
fn mul_sub_precise(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round_ties_even(self) -> Self;
fn fract(self) -> Self;
fn trunc(self) -> Self;
// Provided methods
fn to_int<T: SimdCvtTruncate<Self>>(self) -> T { ... }
fn to_int_precise<T: SimdCvtTruncate<Self>>(self) -> T { ... }
}Expand description
Functionality implemented by floating-point SIMD vectors.
Required Methods§
Sourcefn sqrt(self) -> Self
fn sqrt(self) -> Self
Compute the square root of each element.
Negative elements other than -0.0 will become NaN.
Sourcefn approximate_recip(self) -> Self
fn approximate_recip(self) -> Self
Compute an approximate reciprocal (1. / x) for each element.
This uses a fast hardware estimate where available, and falls back to exact division otherwise.
On x86 for f32, this has a relative error less than 1.5 × 2^-12. On AArch64 (f32 and f64), this has a relative error less than 2^-8. The precision of this operation may change as new platform support is added.
Sourcefn copysign(self, rhs: impl SimdInto<Self, S>) -> Self
fn copysign(self, rhs: impl SimdInto<Self, S>) -> Self
Return a vector with the magnitude of self and the sign of rhs for each element.
This operation copies the sign bit, so if an input element is NaN, the output element will be a NaN with the same payload and a copied sign bit.
Sourcefn mul_add(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self
fn mul_add( self, op1: impl SimdInto<Self, S>, op2: impl SimdInto<Self, S>, ) -> Self
Compute (self * op1) + op2 (fused multiply-add) for each element.
Depending on hardware support, the result may be computed with only one rounding error, or may be implemented as a regular multiply followed by an add, which will result in two rounding errors.
Sourcefn mul_add_precise(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self
fn mul_add_precise( self, op1: impl SimdInto<Self, S>, op2: impl SimdInto<Self, S>, ) -> Self
Compute (self * op1) + op2 for each element, with a single rounding at the end.
The result is the infinite-precision product-plus-add rounded once to the element type. This may be substantially slower than mul_add on hardware without fused multiply-add instructions.
§Precision guarantees
This function is not susceptible to the bug in Rust standard library and in musl libc that causes incorrect rounding for near-zero values on CPUs without hardware support for this operation.
On the tier-2 i586-* targets, this function is correct if and only if SSE2 is available on the CPU.
On WebAssembly this uses the host implementation of precise multiply-add via the madd intrinsic.
The exact NaN payloads as well as signaling NaNs are not preserved.
Sourcefn mul_sub(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self
fn mul_sub( self, op1: impl SimdInto<Self, S>, op2: impl SimdInto<Self, S>, ) -> Self
Compute (self * op1) - op2 (fused multiply-subtract) for each element.
Depending on hardware support, the result may be computed with only one rounding error, or may be implemented as a regular multiply followed by a subtract, which will result in two rounding errors.
Sourcefn mul_sub_precise(
self,
op1: impl SimdInto<Self, S>,
op2: impl SimdInto<Self, S>,
) -> Self
fn mul_sub_precise( self, op1: impl SimdInto<Self, S>, op2: impl SimdInto<Self, S>, ) -> Self
Compute (self * op1) - op2 for each element, with a single rounding at the end.
The result is the infinite-precision product-minus-subtrahend rounded once to the element type. This may be substantially slower than mul_sub on hardware without fused multiply-add instructions.
# Precision guarantees
This function is not susceptible to the bug in Rust standard library and in musl libc that causes incorrect rounding for near-zero values on CPUs without hardware support for this operation.
On the tier-2 i586-* targets, this function is correct if and only if SSE2 is available on the CPU.
On WebAssembly this uses the host implementation of precise multiply-add via the madd intrinsic.
The exact NaN payloads as well as signaling NaNs are not preserved.
Sourcefn floor(self) -> Self
fn floor(self) -> Self
Return the largest integer less than or equal to each element, that is, round towards negative infinity.
Sourcefn ceil(self) -> Self
fn ceil(self) -> Self
Return the smallest integer greater than or equal to each element, that is, round towards positive infinity.
Sourcefn round_ties_even(self) -> Self
fn round_ties_even(self) -> Self
Round each element to the nearest integer, with ties rounding to the nearest even integer.
There is no corresponding round operation. Rust’s round operation rounds ties away from zero, a behavior it inherited from C. That behavior is not implemented across all platforms, whereas round-ties-even is.
Provided Methods§
Sourcefn to_int<T: SimdCvtTruncate<Self>>(self) -> T
fn to_int<T: SimdCvtTruncate<Self>>(self) -> T
Convert this floating-point type to an integer. This is a convenience method that
delegates to SimdCvtTruncate::truncate_from, and can only be called if there
actually exists a target type of the same bit width (u32/i32 for f32, or
u64/i64 for f64).
For more information about the semantics of this specific conversion, see the
concrete SimdCvtTruncate implementations for integer types.
Sourcefn to_int_precise<T: SimdCvtTruncate<Self>>(self) -> T
fn to_int_precise<T: SimdCvtTruncate<Self>>(self) -> T
Convert this floating-point type to an integer, saturating on overflow and returning
0 for NaN. This is a convenience method that delegates to
SimdCvtTruncate::truncate_from_precise, and can only be called if there actually
exists a target type of the same bit width (u32/i32 for f32, or u64/i64
for f64).
For more information about the semantics of this specific conversion, see the
concrete SimdCvtTruncate implementations for integer types.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".