]> git.lizzy.rs Git - rust.git/blob - crates/core_simd/src/round.rs
Reenable rounding ops
[rust.git] / crates / core_simd / src / round.rs
1 macro_rules! implement {
2     {
3         $type:ident, $int_type:ident
4     } => {
5         impl<const LANES: usize> crate::$type<LANES> {
6             /// Returns the largest integer less than or equal to each lane.
7             #[must_use = "method returns a new vector and does not mutate the original value"]
8             #[inline]
9             pub fn floor(self) -> Self {
10                 unsafe { crate::intrinsics::simd_floor(self) }
11             }
12
13             /// Returns the smallest integer greater than or equal to each lane.
14             #[must_use = "method returns a new vector and does not mutate the original value"]
15             #[inline]
16             pub fn ceil(self) -> Self {
17                 unsafe { crate::intrinsics::simd_ceil(self) }
18             }
19
20             /// Rounds toward zero and converts to the same-width integer type, assuming that
21             /// the value is finite and fits in that type.
22             ///
23             /// # Safety
24             /// The value must:
25             ///
26             /// * Not be NaN
27             /// * Not be infinite
28             /// * Be representable in the return type, after truncating off its fractional part
29             #[inline]
30             pub unsafe fn to_int_unchecked(self) -> crate::$int_type<LANES> {
31                 crate::intrinsics::simd_cast(self)
32             }
33
34             /// Creates a floating-point vector from an integer vector.  Rounds values that are
35             /// not exactly representable.
36             #[inline]
37             pub fn round_from_int(value: crate::$int_type<LANES>) -> Self {
38                 unsafe { crate::intrinsics::simd_cast(value) }
39             }
40         }
41     }
42 }
43
44 implement! { SimdF32, SimdI32 }
45 implement! { SimdF64, SimdI64 }