diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2021-04-13 20:19:53 -0700 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2021-04-25 16:42:49 -0700 |
| commit | e8b6bca694098e4865d602ef438458ea52335e6a (patch) | |
| tree | 6753eeff0abdafb430adc98275c665a1d7be8188 | |
| parent | 1f4e902ee70e178f1009e4242b2dac083bb942d4 (diff) | |
| download | rust-e8b6bca694098e4865d602ef438458ea52335e6a.tar.gz rust-e8b6bca694098e4865d602ef438458ea52335e6a.zip | |
Finish fixing up abs docs
| -rw-r--r-- | crates/core_simd/src/math.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/crates/core_simd/src/math.rs b/crates/core_simd/src/math.rs index e987ec4e9c9..baf92ee097b 100644 --- a/crates/core_simd/src/math.rs +++ b/crates/core_simd/src/math.rs @@ -79,6 +79,25 @@ macro_rules! impl_int_arith { unsafe { crate::intrinsics::simd_saturating_sub(self, second) } } + /// Lanewise absolute value, implemented in Rust. + /// Every lane becomes its absolute value. + /// + /// # Examples + /// ``` + /// # use core_simd::*; + #[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")] + #[doc = concat!("let xs = ", stringify!($name), "::from_array([MIN, MIN +1, -5, 0]);")] + #[doc = concat!("assert_eq!(xs.abs(), ", stringify!($name), "::from_array([MIN, MAX, 5, 0]));")] + /// ``` + #[inline] + pub fn abs(self) -> Self { + let mut xs = self.to_array(); + for (i, x) in xs.clone().iter().enumerate() { + xs[i] = x.wrapping_abs() + } + $name::from_array(xs) + } + /// Lanewise saturating absolute value, implemented in Rust. /// As abs(), except the MIN value becomes MAX instead of itself. /// @@ -86,9 +105,11 @@ macro_rules! impl_int_arith { /// ``` /// # use core_simd::*; #[doc = concat!("# use core::", stringify!($n), "::{MIN, MAX};")] - #[doc = concat!("let x = ", stringify!($name), "::from_array([MIN, -2, 0, 3]);")] - /// let abs = x.saturating_abs(); - #[doc = concat!("assert_eq!(abs, ", stringify!($name), "::from_array([MAX, 2, 0, 3]));")] + #[doc = concat!("let xs = ", stringify!($name), "::from_array([MIN, -2, 0, 3]);")] + /// let unsat = xs.abs(); + /// let sat = xs.saturating_abs(); + #[doc = concat!("assert_eq!(unsat, ", stringify!($name), "::from_array([MIN, 2, 0, 3]));")] + #[doc = concat!("assert_eq!(sat, ", stringify!($name), "::from_array([MAX, 2, 0, 3]));")] /// ``` #[inline] pub fn saturating_abs(self) -> Self { |
