11#![ feature( float_gamma) ]
2+ use std:: { f32, f64} ;
23
34macro_rules! assert_approx_eq {
45 ( $a: expr, $b: expr) => { {
@@ -15,8 +16,7 @@ fn ldexp(a: f64, b: i32) -> f64 {
1516}
1617
1718pub fn main ( ) {
18- use std:: f32;
19- use std:: f64;
19+ mul_add ( ) ;
2020
2121 assert_approx_eq ! ( 64f32 . sqrt( ) , 8f32 ) ;
2222 assert_approx_eq ! ( 64f64 . sqrt( ) , 8f64 ) ;
@@ -48,13 +48,6 @@ pub fn main() {
4848 assert_approx_eq ! ( 8f32 . log2( ) , 3f32 ) ;
4949 assert_approx_eq ! ( f64 :: consts:: E . log2( ) , f64 :: consts:: LOG2_E ) ;
5050
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-
5851 assert_approx_eq ! ( ( -1.0f32 ) . abs( ) , 1.0f32 ) ;
5952 assert_approx_eq ! ( 34.2f64 . abs( ) , 34.2f64 ) ;
6053
@@ -146,3 +139,19 @@ pub fn main() {
146139 assert_approx_eq ! ( val, ( 2.0 * f64 :: consts:: PI . sqrt( ) ) . ln( ) ) ;
147140 assert_eq ! ( sign, -1 ) ;
148141}
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