Skip to main content

SimdFloat

Trait SimdFloat 

Source
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> {
    type Bits: SimdInt<S, Element = <Self::Element as SimdFloatElement>::Bits, ByteVector = Self::ByteVector>;

Show 26 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 round(self) -> Self; fn fract(self) -> Self; fn trunc(self) -> Self; fn to_degrees(self) -> Self; fn to_radians(self) -> Self; fn is_nan(self) -> Self::Mask; fn is_infinite(self) -> Self::Mask; fn is_finite(self) -> Self::Mask; fn is_subnormal(self) -> Self::Mask; fn is_normal(self) -> Self::Mask; fn is_sign_positive(self) -> Self::Mask; fn is_sign_negative(self) -> Self::Mask; // Provided methods fn to_bits(self) -> Self::Bits { ... } fn from_bits(bits: Self::Bits) -> Self { ... } 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 Associated Types§

Source

type Bits: SimdInt<S, Element = <Self::Element as SimdFloatElement>::Bits, ByteVector = Self::ByteVector>

Bit representation of this SIMD float vector type.

Required Methods§

Source

fn sqrt(self) -> Self

Compute the square root of each element.

Negative elements other than -0.0 will become NaN.

Source

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.

Source

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.

Source

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 platform 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.

Source

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 platforms without fused multiply-add instructions, including WebAssembly.

§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.

The exact NaN payloads as well as signaling NaNs are not preserved.

Source

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 platform 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.

Source

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 platforms without fused multiply-add instructions, including WebAssembly. # 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.

The exact NaN payloads as well as signaling NaNs are not preserved.

Source

fn floor(self) -> Self

Return the largest integer less than or equal to each element, that is, round towards negative infinity.

Source

fn ceil(self) -> Self

Return the smallest integer greater than or equal to each element, that is, round towards positive infinity.

Source

fn round_ties_even(self) -> Self

Round each element to the nearest integer, with ties rounding to the nearest even integer.

Source

fn round(self) -> Self

Round each element to the nearest integer, with ties rounding away from zero.

§Performance considerations

Only AArch64 has native instructions for this operation. round has to be emulated on all other platforms which is around 2-4x slower than round_ties_even. Prefer using round_ties_even if possible.

Source

fn fract(self) -> Self

Return the fractional part of each element.

This is equivalent to self - self.trunc().

Source

fn trunc(self) -> Self

Return the integer part of each element, rounding towards zero.

Source

fn to_degrees(self) -> Self

Converts radians to degrees.

The precision of this function is non-deterministic. This means it varies by platform, Rust version, and can even differ within the same execution from one invocation to the next.

Source

fn to_radians(self) -> Self

Converts degrees to radians.

The precision of this function is non-deterministic. This means it varies by platform, Rust version, and can even differ within the same execution from one invocation to the next.

Source

fn is_nan(self) -> Self::Mask

Return a mask indicating which elements are NaN.

Source

fn is_infinite(self) -> Self::Mask

Return a mask indicating which elements are positive or negative infinite.

Source

fn is_finite(self) -> Self::Mask

Return a mask indicating which elements are neither infinite nor NaN.

Source

fn is_subnormal(self) -> Self::Mask

Return a mask indicating which elements are subnormal.

This classifies the stored bit pattern, even when floating-point operations treat subnormals as zero.

Source

fn is_normal(self) -> Self::Mask

Return a mask indicating which elements are neither zero, infinite, subnormal, or NaN.

Source

fn is_sign_positive(self) -> Self::Mask

Return a mask indicating which elements have a positive sign, including +0.0, NaNs with positive sign bit and positive infinity.

NaN inputs may produce an unexpected or non-portable result, see f32::is_sign_positive for details.

Source

fn is_sign_negative(self) -> Self::Mask

Return a mask indicating which elements have a negative sign, including -0.0, NaNs with negative sign bit and negative infinity.

NaN inputs may produce an unexpected or non-portable result, see f32::is_sign_negative for details.

Provided Methods§

Source

fn to_bits(self) -> Self::Bits

Raw transmutation to an unsigned integer vector type with the same size and number of elements.

This is analogous to f32::to_bits and f64::to_bits.

Source

fn from_bits(bits: Self::Bits) -> Self

Raw transmutation from an unsigned integer vector type with the same size and number of elements.

This is analogous to f32::from_bits and f64::from_bits.

Source

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.

Source

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".

Implementors§

Source§

impl<S: Simd> SimdFloat<S> for f32x4<S>

Source§

impl<S: Simd> SimdFloat<S> for f32x8<S>

Source§

impl<S: Simd> SimdFloat<S> for f32x16<S>

Source§

impl<S: Simd> SimdFloat<S> for f64x2<S>

Source§

impl<S: Simd> SimdFloat<S> for f64x4<S>

Source§

impl<S: Simd> SimdFloat<S> for f64x8<S>