Trait SimdFloat
pub trait SimdFloat: Copy
Operations on SIMD vectors of floats.
Associated Types
type Mask;Mask type used for manipulating this SIMD vector type.
type Scalar;Scalar type contained by this SIMD vector type.
type Bits;Bit representation of this SIMD vector type.
type Cast<T: SimdElement>;A SIMD vector with a different element type.
Required Methods
fn cast<T: SimdCast>(self) -> Self::Cast<T>Performs elementwise conversion of this vector's elements to another SIMD-valid type.
This follows the semantics of Rust's
asconversion for floats (truncating or saturating at the limits) for each element.Example
# # use simd; # use simd; # use *; let floats: = from_array; let ints = floats.; assert_eq!; // Formally equivalent, but `Simd::cast` can optimize better. assert_eq!; // The float conversion does not round-trip. let floats_again = ints.cast; assert_ne!; assert_eq!;unsafe fn to_int_unchecked<I: SimdCast>(self) -> Self::Cast<I> where Self::Scalar: FloatToInt<I>,Rounds toward zero and converts to the same-width integer type, assuming that the value is finite and fits in that type.
Safety
The value must:
- Not be NaN
- Not be infinite
- Be representable in the return type, after truncating off its fractional part
If these requirements are infeasible or costly, consider using the safe function cast, which saturates on conversion.
fn to_bits(self) -> Self::BitsRaw transmutation to an unsigned integer vector type with the same size and number of elements.
fn from_bits(bits: Self::Bits) -> SelfRaw transmutation from an unsigned integer vector type with the same size and number of elements.
fn abs(self) -> SelfProduces a vector where every element has the absolute value of the equivalently-indexed element in
self.fn recip(self) -> SelfTakes the reciprocal (inverse) of each element,
1/x.fn to_degrees(self) -> SelfConverts each element from radians to degrees.
fn to_radians(self) -> SelfConverts each element from degrees to radians.
fn is_sign_positive(self) -> Self::MaskReturns true for each element if it has a positive sign, including
+0.0,NaNs with positive sign bit and positive infinity.fn is_sign_negative(self) -> Self::MaskReturns true for each element if it has a negative sign, including
-0.0,NaNs with negative sign bit and negative infinity.fn is_nan(self) -> Self::MaskReturns true for each element if its value is
NaN.fn is_infinite(self) -> Self::MaskReturns true for each element if its value is positive infinity or negative infinity.
fn is_finite(self) -> Self::MaskReturns true for each element if its value is neither infinite nor
NaN.fn is_subnormal(self) -> Self::MaskReturns true for each element if its value is subnormal.
fn is_normal(self) -> Self::MaskReturns true for each element if its value is neither zero, infinite, subnormal, nor
NaN.fn signum(self) -> SelfReplaces each element with a number that represents its sign.
1.0if the number is positive,+0.0, orINFINITY-1.0if the number is negative,-0.0, orNEG_INFINITYNANif the number isNAN
fn copysign(self, sign: Self) -> SelfReturns each element with the magnitude of
selfand the sign ofsign.For any element containing a
NAN, aNANwith the sign ofsignis returned.fn simd_min(self, other: Self) -> SelfReturns the minimum of each element.
If one of the values is
NAN, then the other value is returned.fn simd_max(self, other: Self) -> SelfReturns the maximum of each element.
If one of the values is
NAN, then the other value is returned.fn simd_clamp(self, min: Self, max: Self) -> SelfRestrict each element to a certain interval unless it is NaN.
For each element in
self, returns the corresponding element inmaxif the element is greater thanmax, and the corresponding element inminif the element is less thanmin. Otherwise returns the element inself.fn reduce_sum(self) -> Self::ScalarReturns the sum of the elements of the vector.
Examples
# # use simd; # use simd; # use *; let v = from_array; assert_eq!;fn reduce_product(self) -> Self::ScalarReducing multiply. Returns the product of the elements of the vector.
Examples
# # use simd; # use simd; # use *; let v = from_array; assert_eq!;fn reduce_max(self) -> Self::ScalarReturns the maximum element in the vector.
Returns values based on equality, so a vector containing both
0.and-0.may return either.This function will not return
NaNunless all elements areNaN.Examples
# # use simd; # use simd; # use *; let v = from_array; assert_eq!; // NaN values are skipped... let v = from_array; assert_eq!; // ...unless all values are NaN let v = from_array; assert!;fn reduce_min(self) -> Self::ScalarReturns the minimum element in the vector.
Returns values based on equality, so a vector containing both
0.and-0.may return either.This function will not return
NaNunless all elements areNaN.Examples
# # use simd; # use simd; # use *; let v = from_array; assert_eq!; // NaN values are skipped... let v = from_array; assert_eq!; // ...unless all values are NaN let v = from_array; assert!;