@@ -220,6 +220,70 @@ bitops! {
220220 }
221221}
222222
223+ macro_rules! float_arith {
224+ ( $( impl <const LANES : usize > FloatArith for Simd <$float: ty, LANES > {
225+ fn add( self , rhs: Self ) -> Self :: Output ;
226+ fn mul( self , rhs: Self ) -> Self :: Output ;
227+ fn sub( self , rhs: Self ) -> Self :: Output ;
228+ fn div( self , rhs: Self ) -> Self :: Output ;
229+ fn rem( self , rhs: Self ) -> Self :: Output ;
230+ } ) * ) => {
231+ $(
232+ unsafe_base_op!{
233+ impl <const LANES : usize > Add for Simd <$float, LANES > {
234+ fn add( self , rhs: Self ) -> Self :: Output {
235+ unsafe { simd_add }
236+ }
237+ }
238+
239+ impl <const LANES : usize > Mul for Simd <$float, LANES > {
240+ fn mul( self , rhs: Self ) -> Self :: Output {
241+ unsafe { simd_mul }
242+ }
243+ }
244+
245+ impl <const LANES : usize > Sub for Simd <$float, LANES > {
246+ fn sub( self , rhs: Self ) -> Self :: Output {
247+ unsafe { simd_sub }
248+ }
249+ }
250+
251+ impl <const LANES : usize > Div for Simd <$float, LANES > {
252+ fn div( self , rhs: Self ) -> Self :: Output {
253+ unsafe { simd_div }
254+ }
255+ }
256+
257+ impl <const LANES : usize > Rem for Simd <$float, LANES > {
258+ fn rem( self , rhs: Self ) -> Self :: Output {
259+ unsafe { simd_rem }
260+ }
261+ }
262+ }
263+ ) *
264+ } ;
265+ }
266+
267+ // We don't need any special precautions here:
268+ // Floats always accept arithmetic ops, but may become NaN.
269+ float_arith ! {
270+ impl <const LANES : usize > FloatArith for Simd <f32 , LANES > {
271+ fn add( self , rhs: Self ) -> Self :: Output ;
272+ fn mul( self , rhs: Self ) -> Self :: Output ;
273+ fn sub( self , rhs: Self ) -> Self :: Output ;
274+ fn div( self , rhs: Self ) -> Self :: Output ;
275+ fn rem( self , rhs: Self ) -> Self :: Output ;
276+ }
277+
278+ impl <const LANES : usize > FloatArith for Simd <f64 , LANES > {
279+ fn add( self , rhs: Self ) -> Self :: Output ;
280+ fn mul( self , rhs: Self ) -> Self :: Output ;
281+ fn sub( self , rhs: Self ) -> Self :: Output ;
282+ fn div( self , rhs: Self ) -> Self :: Output ;
283+ fn rem( self , rhs: Self ) -> Self :: Output ;
284+ }
285+ }
286+
223287/// Automatically implements operators over references in addition to the provided operator.
224288macro_rules! impl_ref_ops {
225289 // binary op
@@ -284,19 +348,6 @@ macro_rules! impl_op {
284348 } ;
285349}
286350
287- /// Implements floating-point operators for the provided types.
288- macro_rules! impl_float_ops {
289- { $( $scalar: ty) ,* } => {
290- $(
291- impl_op! { impl Add for $scalar }
292- impl_op! { impl Sub for $scalar }
293- impl_op! { impl Mul for $scalar }
294- impl_op! { impl Div for $scalar }
295- impl_op! { impl Rem for $scalar }
296- ) *
297- } ;
298- }
299-
300351/// Implements unsigned integer operators for the provided types.
301352macro_rules! impl_unsigned_int_ops {
302353 { $( $scalar: ty) ,* } => {
@@ -375,4 +426,3 @@ macro_rules! impl_signed_int_ops {
375426
376427impl_unsigned_int_ops ! { u8 , u16 , u32 , u64 , usize }
377428impl_signed_int_ops ! { i8 , i16 , i32 , i64 , isize }
378- impl_float_ops ! { f32 , f64 }
0 commit comments