@@ -34,6 +34,10 @@ trait TestableFloat: Sized {
34
34
const RAW_12_DOT_5 : Self ;
35
35
const RAW_1337 : Self ;
36
36
const RAW_MINUS_14_DOT_25 : Self ;
37
+ /// The result of 12.3.mul_add(4.5, 6.7)
38
+ const MUL_ADD_RESULT : Self ;
39
+ /// The result of (-12.3).mul_add(-4.5, -6.7)
40
+ const NEG_MUL_ADD_RESULT : Self ;
37
41
}
38
42
39
43
impl TestableFloat for f16 {
@@ -58,6 +62,8 @@ impl TestableFloat for f16 {
58
62
const RAW_12_DOT_5 : Self = Self :: from_bits ( 0x4a40 ) ;
59
63
const RAW_1337 : Self = Self :: from_bits ( 0x6539 ) ;
60
64
const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xcb20 ) ;
65
+ const MUL_ADD_RESULT : Self = 62.031 ;
66
+ const NEG_MUL_ADD_RESULT : Self = 48.625 ;
61
67
}
62
68
63
69
impl TestableFloat for f32 {
@@ -84,6 +90,8 @@ impl TestableFloat for f32 {
84
90
const RAW_12_DOT_5 : Self = Self :: from_bits ( 0x41480000 ) ;
85
91
const RAW_1337 : Self = Self :: from_bits ( 0x44a72000 ) ;
86
92
const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xc1640000 ) ;
93
+ const MUL_ADD_RESULT : Self = 62.05 ;
94
+ const NEG_MUL_ADD_RESULT : Self = 48.65 ;
87
95
}
88
96
89
97
impl TestableFloat for f64 {
@@ -106,6 +114,8 @@ impl TestableFloat for f64 {
106
114
const RAW_12_DOT_5 : Self = Self :: from_bits ( 0x4029000000000000 ) ;
107
115
const RAW_1337 : Self = Self :: from_bits ( 0x4094e40000000000 ) ;
108
116
const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xc02c800000000000 ) ;
117
+ const MUL_ADD_RESULT : Self = 62.050000000000004 ;
118
+ const NEG_MUL_ADD_RESULT : Self = 48.650000000000006 ;
109
119
}
110
120
111
121
impl TestableFloat for f128 {
@@ -128,6 +138,8 @@ impl TestableFloat for f128 {
128
138
const RAW_12_DOT_5 : Self = Self :: from_bits ( 0x40029000000000000000000000000000 ) ;
129
139
const RAW_1337 : Self = Self :: from_bits ( 0x40094e40000000000000000000000000 ) ;
130
140
const RAW_MINUS_14_DOT_25 : Self = Self :: from_bits ( 0xc002c800000000000000000000000000 ) ;
141
+ const MUL_ADD_RESULT : Self = 62.0500000000000000000000000000000037 ;
142
+ const NEG_MUL_ADD_RESULT : Self = 48.6500000000000000000000000000000049 ;
131
143
}
132
144
133
145
/// Determine the tolerance for values of the argument type.
@@ -359,8 +371,6 @@ macro_rules! float_test {
359
371
360
372
mod f128;
361
373
mod f16;
362
- mod f32;
363
- mod f64;
364
374
365
375
float_test ! {
366
376
name: num,
@@ -1542,3 +1552,28 @@ float_test! {
1542
1552
assert_biteq!( Float :: from_bits( masked_nan2) , Float :: from_bits( masked_nan2) ) ;
1543
1553
}
1544
1554
}
1555
+
1556
+ float_test ! {
1557
+ name: mul_add,
1558
+ attrs: {
1559
+ f16: #[ cfg( any( miri, target_has_reliable_f16) ) ] ,
1560
+ // FIXME(#140515): mingw has an incorrect fma https://sourceforge.net/p/mingw-w64/bugs/848/
1561
+ f32 : #[ cfg_attr( all( target_os = "windows" , target_env = "gnu" , not( target_abi = "llvm" ) ) , ignore) ] ,
1562
+ f64 : #[ cfg_attr( all( target_os = "windows" , target_env = "gnu" , not( target_abi = "llvm" ) ) , ignore) ] ,
1563
+ f128: #[ cfg( any( miri, target_has_reliable_f128) ) ] ,
1564
+ } ,
1565
+ test<Float > {
1566
+ let nan: Float = Float :: NAN ;
1567
+ let inf: Float = Float :: INFINITY ;
1568
+ let neg_inf: Float = Float :: NEG_INFINITY ;
1569
+ assert_biteq!( flt( 12.3 ) . mul_add( 4.5 , 6.7 ) , Float :: MUL_ADD_RESULT ) ;
1570
+ assert_biteq!( ( flt( -12.3 ) ) . mul_add( -4.5 , -6.7 ) , Float :: NEG_MUL_ADD_RESULT ) ;
1571
+ assert_biteq!( flt( 0.0 ) . mul_add( 8.9 , 1.2 ) , 1.2 ) ;
1572
+ assert_biteq!( flt( 3.4 ) . mul_add( -0.0 , 5.6 ) , 5.6 ) ;
1573
+ assert!( nan. mul_add( 7.8 , 9.0 ) . is_nan( ) ) ;
1574
+ assert_biteq!( inf. mul_add( 7.8 , 9.0 ) , inf) ;
1575
+ assert_biteq!( neg_inf. mul_add( 7.8 , 9.0 ) , neg_inf) ;
1576
+ assert_biteq!( flt( 8.9 ) . mul_add( inf, 3.2 ) , inf) ;
1577
+ assert_biteq!( ( flt( -3.2 ) ) . mul_add( 2.4 , neg_inf) , neg_inf) ;
1578
+ }
1579
+ }
0 commit comments