pub trait SimdFloat: Copy + Sealed {
type Mask;
type Scalar;
type Bits;
type Cast<T: SimdElement>;
Show 24 methods
// Required methods
fn cast<T: SimdCast>(self) -> Self::Cast<T>;
unsafe fn to_int_unchecked<I: SimdCast>(self) -> Self::Cast<I>
where Self::Scalar: FloatToInt<I>;
fn to_bits(self) -> Self::Bits;
fn from_bits(bits: Self::Bits) -> Self;
fn abs(self) -> Self;
fn recip(self) -> Self;
fn to_degrees(self) -> Self;
fn to_radians(self) -> Self;
fn is_sign_positive(self) -> Self::Mask;
fn is_sign_negative(self) -> Self::Mask;
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 signum(self) -> Self;
fn copysign(self, sign: Self) -> Self;
fn simd_min(self, other: Self) -> Self;
fn simd_max(self, other: Self) -> Self;
fn simd_clamp(self, min: Self, max: Self) -> Self;
fn reduce_sum(self) -> Self::Scalar;
fn reduce_product(self) -> Self::Scalar;
fn reduce_max(self) -> Self::Scalar;
fn reduce_min(self) -> Self::Scalar;
}
portable_simd
#86656)Expand description
Operations on SIMD vectors of floats.
Required Associated Types§
Sourcetype Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
type Mask
portable_simd
#86656)Mask type used for manipulating this SIMD vector type.
Sourcetype Scalar
🔬This is a nightly-only experimental API. (portable_simd
#86656)
type Scalar
portable_simd
#86656)Scalar type contained by this SIMD vector type.
Sourcetype Bits
🔬This is a nightly-only experimental API. (portable_simd
#86656)
type Bits
portable_simd
#86656)Bit representation of this SIMD vector type.
Sourcetype Cast<T: SimdElement>
🔬This is a nightly-only experimental API. (portable_simd
#86656)
type Cast<T: SimdElement>
portable_simd
#86656)A SIMD vector with a different element type.
Required Methods§
Sourcefn cast<T: SimdCast>(self) -> Self::Cast<T>
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn cast<T: SimdCast>(self) -> Self::Cast<T>
portable_simd
#86656)Performs elementwise conversion of this vector’s elements to another SIMD-valid type.
This follows the semantics of Rust’s as
conversion for floats (truncating or saturating
at the limits) for each element.
§Example
let floats: Simd<f32, 4> = Simd::from_array([1.9, -4.5, f32::INFINITY, f32::NAN]);
let ints = floats.cast::<i32>();
assert_eq!(ints, Simd::from_array([1, -4, i32::MAX, 0]));
// Formally equivalent, but `Simd::cast` can optimize better.
assert_eq!(ints, Simd::from_array(floats.to_array().map(|x| x as i32)));
// The float conversion does not round-trip.
let floats_again = ints.cast();
assert_ne!(floats, floats_again);
assert_eq!(floats_again, Simd::from_array([1.0, -4.0, 2147483647.0, 0.0]));
Sourceunsafe fn to_int_unchecked<I: SimdCast>(self) -> Self::Cast<I>where
Self::Scalar: FloatToInt<I>,
🔬This is a nightly-only experimental API. (portable_simd
#86656)
unsafe fn to_int_unchecked<I: SimdCast>(self) -> Self::Cast<I>where
Self::Scalar: FloatToInt<I>,
portable_simd
#86656)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.
Sourcefn to_bits(self) -> Self::Bits
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn to_bits(self) -> Self::Bits
portable_simd
#86656)Raw transmutation to an unsigned integer vector type with the same size and number of elements.
Sourcefn from_bits(bits: Self::Bits) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn from_bits(bits: Self::Bits) -> Self
portable_simd
#86656)Raw transmutation from an unsigned integer vector type with the same size and number of elements.
Sourcefn abs(self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn abs(self) -> Self
portable_simd
#86656)Produces a vector where every element has the absolute value of the
equivalently-indexed element in self
.
Sourcefn recip(self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn recip(self) -> Self
portable_simd
#86656)Takes the reciprocal (inverse) of each element, 1/x
.
Sourcefn to_degrees(self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn to_degrees(self) -> Self
portable_simd
#86656)Converts each element from radians to degrees.
Sourcefn to_radians(self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn to_radians(self) -> Self
portable_simd
#86656)Converts each element from degrees to radians.
Sourcefn is_sign_positive(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_sign_positive(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if it has a positive sign, including
+0.0
, NaN
s with positive sign bit and positive infinity.
Sourcefn is_sign_negative(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_sign_negative(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if it has a negative sign, including
-0.0
, NaN
s with negative sign bit and negative infinity.
Sourcefn is_nan(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_nan(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if its value is NaN
.
Sourcefn is_infinite(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_infinite(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if its value is positive infinity or negative infinity.
Sourcefn is_finite(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_finite(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if its value is neither infinite nor NaN
.
Sourcefn is_subnormal(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_subnormal(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if its value is subnormal.
Sourcefn is_normal(self) -> Self::Mask
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn is_normal(self) -> Self::Mask
portable_simd
#86656)Returns true for each element if its value is neither zero, infinite,
subnormal, nor NaN
.
Sourcefn signum(self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn signum(self) -> Self
portable_simd
#86656)Replaces each element with a number that represents its sign.
1.0
if the number is positive,+0.0
, orINFINITY
-1.0
if the number is negative,-0.0
, orNEG_INFINITY
NAN
if the number isNAN
Sourcefn copysign(self, sign: Self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn copysign(self, sign: Self) -> Self
portable_simd
#86656)Returns each element with the magnitude of self
and the sign of sign
.
For any element containing a NAN
, a NAN
with the sign of sign
is returned.
Sourcefn simd_min(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn simd_min(self, other: Self) -> Self
portable_simd
#86656)Returns the minimum of each element.
If one of the values is NAN
, then the other value is returned.
Sourcefn simd_max(self, other: Self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn simd_max(self, other: Self) -> Self
portable_simd
#86656)Returns the maximum of each element.
If one of the values is NAN
, then the other value is returned.
Sourcefn simd_clamp(self, min: Self, max: Self) -> Self
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn simd_clamp(self, min: Self, max: Self) -> Self
portable_simd
#86656)Restrict each element to a certain interval unless it is NaN.
For each element in self
, returns the corresponding element in max
if the element is
greater than max
, and the corresponding element in min
if the element is less
than min
. Otherwise returns the element in self
.
Sourcefn reduce_sum(self) -> Self::Scalar
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn reduce_sum(self) -> Self::Scalar
portable_simd
#86656)Returns the sum of the elements of the vector.
§Examples
Sourcefn reduce_product(self) -> Self::Scalar
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn reduce_product(self) -> Self::Scalar
portable_simd
#86656)Reducing multiply. Returns the product of the elements of the vector.
§Examples
Sourcefn reduce_max(self) -> Self::Scalar
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn reduce_max(self) -> Self::Scalar
portable_simd
#86656)Returns 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 NaN
unless all elements are NaN
.
§Examples
Sourcefn reduce_min(self) -> Self::Scalar
🔬This is a nightly-only experimental API. (portable_simd
#86656)
fn reduce_min(self) -> Self::Scalar
portable_simd
#86656)Returns 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 NaN
unless all elements are NaN
.
§Examples
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.