1
1
#![ feature( float_gamma) ]
2
+ use std:: { f32, f64} ;
2
3
3
4
macro_rules! assert_approx_eq {
4
5
( $a: expr, $b: expr) => { {
@@ -15,8 +16,7 @@ fn ldexp(a: f64, b: i32) -> f64 {
15
16
}
16
17
17
18
pub fn main ( ) {
18
- use std:: f32;
19
- use std:: f64;
19
+ mul_add ( ) ;
20
20
21
21
assert_approx_eq ! ( 64f32 . sqrt( ) , 8f32 ) ;
22
22
assert_approx_eq ! ( 64f64 . sqrt( ) , 8f64 ) ;
@@ -48,13 +48,6 @@ pub fn main() {
48
48
assert_approx_eq ! ( 8f32 . log2( ) , 3f32 ) ;
49
49
assert_approx_eq ! ( f64 :: consts:: E . log2( ) , f64 :: consts:: LOG2_E ) ;
50
50
51
- assert_approx_eq ! ( 3.0f32 . mul_add( 2.0f32 , 5.0f32 ) , 11.0 ) ;
52
- assert_eq ! ( 0.0f32 . mul_add( -2.0 , f32 :: consts:: E ) , f32 :: consts:: E ) ;
53
- assert_approx_eq ! ( 3.0f64 . mul_add( 2.0 , 5.0 ) , 11.0 ) ;
54
- assert_eq ! ( 0.0f64 . mul_add( -2.0f64 , f64 :: consts:: E ) , f64 :: consts:: E ) ;
55
- assert_eq ! ( ( -3.2f32 ) . mul_add( 2.4 , f32 :: NEG_INFINITY ) , f32 :: NEG_INFINITY ) ;
56
- assert_eq ! ( ( -3.2f64 ) . mul_add( 2.4 , f64 :: NEG_INFINITY ) , f64 :: NEG_INFINITY ) ;
57
-
58
51
assert_approx_eq ! ( ( -1.0f32 ) . abs( ) , 1.0f32 ) ;
59
52
assert_approx_eq ! ( 34.2f64 . abs( ) , 34.2f64 ) ;
60
53
@@ -146,3 +139,19 @@ pub fn main() {
146
139
assert_approx_eq ! ( val, ( 2.0 * f64 :: consts:: PI . sqrt( ) ) . ln( ) ) ;
147
140
assert_eq ! ( sign, -1 ) ;
148
141
}
142
+
143
+ fn mul_add ( ) {
144
+ assert_approx_eq ! ( 3.0f32 . mul_add( 2.0f32 , 5.0f32 ) , 11.0 ) ;
145
+ assert_eq ! ( 0.0f32 . mul_add( -2.0 , f32 :: consts:: E ) , f32 :: consts:: E ) ;
146
+ assert_approx_eq ! ( 3.0f64 . mul_add( 2.0 , 5.0 ) , 11.0 ) ;
147
+ assert_eq ! ( 0.0f64 . mul_add( -2.0f64 , f64 :: consts:: E ) , f64 :: consts:: E ) ;
148
+ assert_eq ! ( ( -3.2f32 ) . mul_add( 2.4 , f32 :: NEG_INFINITY ) , f32 :: NEG_INFINITY ) ;
149
+ assert_eq ! ( ( -3.2f64 ) . mul_add( 2.4 , f64 :: NEG_INFINITY ) , f64 :: NEG_INFINITY ) ;
150
+
151
+ let f = f32:: mul_add (
152
+ -0.000000000000000000000000000000000000014728589 ,
153
+ 0.0000037105144 ,
154
+ 0.000000000000000000000000000000000000000000055 ,
155
+ ) ;
156
+ assert_eq ! ( f. to_bits( ) , f32 :: to_bits( -0.0 ) ) ;
157
+ }
0 commit comments