File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -212,7 +212,20 @@ macro_rules! impl_op {
212
212
impl core:: ops:: Neg for $type {
213
213
type Output = Self ;
214
214
fn neg( self ) -> Self :: Output {
215
- <$type>:: splat( -<$scalar>:: default ( ) ) - self
215
+ <$type>:: splat( 0 ) - self
216
+ }
217
+ }
218
+ }
219
+ } ;
220
+
221
+ { impl Neg for $type: ty, $scalar: ty, @float } => {
222
+ impl_ref_ops! {
223
+ impl core:: ops:: Neg for $type {
224
+ type Output = Self ;
225
+ fn neg( self ) -> Self :: Output {
226
+ // FIXME: Replace this with fneg intrinsic once available.
227
+ // https://github.com/rust-lang/stdsimd/issues/32
228
+ Self :: from_bits( <$type>:: splat( -0.0 ) . to_bits( ) ^ self . to_bits( ) )
216
229
}
217
230
}
218
231
}
@@ -310,7 +323,7 @@ macro_rules! impl_float_ops {
310
323
impl_op! { impl Mul for $vector, $scalar }
311
324
impl_op! { impl Div for $vector, $scalar }
312
325
impl_op! { impl Rem for $vector, $scalar }
313
- impl_op! { impl Neg for $vector, $scalar }
326
+ impl_op! { impl Neg for $vector, $scalar, @float }
314
327
impl_op! { impl Index for $vector, $scalar }
315
328
) *
316
329
) *
Original file line number Diff line number Diff line change @@ -289,6 +289,15 @@ macro_rules! float_tests {
289
289
assert_biteq!( -v, expected) ;
290
290
}
291
291
292
+ #[ test]
293
+ #[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
294
+ fn neg_odd_floats( ) {
295
+ for v in slice_chunks( & C ) {
296
+ let expected = apply_unary_lanewise( v, core:: ops:: Neg :: neg) ;
297
+ assert_biteq!( -v, expected) ;
298
+ }
299
+ }
300
+
292
301
#[ test]
293
302
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
294
303
fn abs_negative( ) {
You can’t perform that action at this time.
0 commit comments