@@ -79,16 +79,37 @@ macro_rules! impl_int_arith {
79
79
unsafe { crate :: intrinsics:: simd_saturating_sub( self , second) }
80
80
}
81
81
82
+ /// Lanewise absolute value, implemented in Rust.
83
+ /// Every lane becomes its absolute value.
84
+ ///
85
+ /// # Examples
86
+ /// ```
87
+ /// # use core_simd::*;
88
+ #[ doc = concat!( "# use core::" , stringify!( $n) , "::{MIN, MAX};" ) ]
89
+ #[ doc = concat!( "let xs = " , stringify!( $name) , "::from_array([MIN, MIN +1, -5, 0]);" ) ]
90
+ #[ doc = concat!( "assert_eq!(xs.abs(), " , stringify!( $name) , "::from_array([MIN, MAX, 5, 0]));" ) ]
91
+ /// ```
92
+ #[ inline]
93
+ pub fn abs( self ) -> Self {
94
+ let mut xs = self . to_array( ) ;
95
+ for ( i, x) in xs. clone( ) . iter( ) . enumerate( ) {
96
+ xs[ i] = x. wrapping_abs( )
97
+ }
98
+ $name:: from_array( xs)
99
+ }
100
+
82
101
/// Lanewise saturating absolute value, implemented in Rust.
83
102
/// As abs(), except the MIN value becomes MAX instead of itself.
84
103
///
85
104
/// # Examples
86
105
/// ```
87
106
/// # use core_simd::*;
88
107
#[ doc = concat!( "# use core::" , stringify!( $n) , "::{MIN, MAX};" ) ]
89
- #[ doc = concat!( "let x = " , stringify!( $name) , "::from_array([MIN, -2, 0, 3]);" ) ]
90
- /// let abs = x.saturating_abs();
91
- #[ doc = concat!( "assert_eq!(abs, " , stringify!( $name) , "::from_array([MAX, 2, 0, 3]));" ) ]
108
+ #[ doc = concat!( "let xs = " , stringify!( $name) , "::from_array([MIN, -2, 0, 3]);" ) ]
109
+ /// let unsat = xs.abs();
110
+ /// let sat = xs.saturating_abs();
111
+ #[ doc = concat!( "assert_eq!(unsat, " , stringify!( $name) , "::from_array([MIN, 2, 0, 3]));" ) ]
112
+ #[ doc = concat!( "assert_eq!(sat, " , stringify!( $name) , "::from_array([MAX, 2, 0, 3]));" ) ]
92
113
/// ```
93
114
#[ inline]
94
115
pub fn saturating_abs( self ) -> Self {
0 commit comments