1 use crate::simd::intrinsics;
2 use crate::simd::{LaneCount, Simd, SupportedLaneCount};
4 macro_rules! implement {
8 #[cfg(feature = "std")]
9 impl<const LANES: usize> Simd<$type, LANES>
11 LaneCount<LANES>: SupportedLaneCount,
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"]
16 pub fn ceil(self) -> Self {
17 unsafe { intrinsics::simd_ceil(self) }
20 /// Returns the largest integer value less than or equal to each lane.
21 #[must_use = "method returns a new vector and does not mutate the original value"]
23 pub fn floor(self) -> Self {
24 unsafe { intrinsics::simd_floor(self) }
27 /// Rounds to the nearest integer value. Ties round toward zero.
28 #[must_use = "method returns a new vector and does not mutate the original value"]
30 pub fn round(self) -> Self {
31 unsafe { intrinsics::simd_round(self) }
34 /// Returns the floating point's integer value, with its fractional part removed.
35 #[must_use = "method returns a new vector and does not mutate the original value"]
37 pub fn trunc(self) -> Self {
38 unsafe { intrinsics::simd_trunc(self) }
41 /// Returns the floating point's fractional value, with its integer part removed.
42 #[must_use = "method returns a new vector and does not mutate the original value"]
44 pub fn fract(self) -> Self {
49 impl<const LANES: usize> Simd<$type, LANES>
51 LaneCount<LANES>: SupportedLaneCount,
53 /// Rounds toward zero and converts to the same-width integer type, assuming that
54 /// the value is finite and fits in that type.
61 /// * Be representable in the return type, after truncating off its fractional part
63 pub unsafe fn to_int_unchecked(self) -> Simd<$int_type, LANES> {
64 unsafe { intrinsics::simd_cast(self) }
67 /// Creates a floating-point vector from an integer vector. Rounds values that are
68 /// not exactly representable.
70 pub fn round_from_int(value: Simd<$int_type, LANES>) -> Self {
71 unsafe { intrinsics::simd_cast(value) }
77 implement! { f32, i32 }
78 implement! { f64, i64 }