@@ -44,6 +44,31 @@ macro_rules! assert_approx_eq {
44
44
} ;
45
45
}
46
46
47
+
48
+ /// From IEEE 754 a Signaling NaN for single precision has the following representation:
49
+ /// ```
50
+ /// s | 1111 1111 | 0x..x
51
+ /// ````
52
+ /// Were at least one `x` is a 1.
53
+ ///
54
+ /// This sNaN has the following representation and is used for testing purposes.:
55
+ /// ```
56
+ /// 0 | 1111111 | 01..0
57
+ /// ```
58
+ const SINGLE_SNAN : f32 = f32:: from_bits ( 0x7fa00000 ) ;
59
+
60
+ /// From IEEE 754 a Signaling NaN for double precision has the following representation:
61
+ /// ```
62
+ /// s | 1111 1111 111 | 0x..x
63
+ /// ````
64
+ /// Were at least one `x` is a 1.
65
+ ///
66
+ /// This sNaN has the following representation and is used for testing purposes.:
67
+ /// ```
68
+ /// 0 | 1111 1111 111 | 01..0
69
+ /// ```
70
+ const DOUBLE_SNAN : f64 = f64:: from_bits ( 0x7ff4000000000000 ) ;
71
+
47
72
fn main ( ) {
48
73
basic ( ) ;
49
74
casts ( ) ;
@@ -1018,6 +1043,16 @@ pub fn libm() {
1018
1043
assert_eq ! ( 1f32 . powf( f32 :: NAN ) , 1f32 ) ;
1019
1044
assert_eq ! ( 1f64 . powf( f64 :: NAN ) , 1f64 ) ;
1020
1045
1046
+ // For pown (powi in rust) the C standard says:
1047
+ // x^0 = 1 for all x not a sNaN.
1048
+ assert_ne ! ( ( SINGLE_SNAN ) . powi( 0 ) , 1.0 ) ;
1049
+ assert_ne ! ( ( DOUBLE_SNAN ) . powi( 0 ) , 1.0 ) ;
1050
+ assert_ne ! ( ( SINGLE_SNAN ) . powi( 0 ) , 1.0 ) ;
1051
+ assert_ne ! ( ( DOUBLE_SNAN ) . powi( 0 ) , 1.0 ) ;
1052
+ // f*::NAN is a quiet NAN and should return 1.
1053
+ assert_eq ! ( f32 :: NAN . powi( 0 ) , 1f32 ) ;
1054
+ assert_eq ! ( f64 :: NAN . powi( 0 ) , 1f64 ) ;
1055
+
1021
1056
assert_eq ! ( ( -1f32 ) . powf( f32 :: INFINITY ) , 1f32 ) ;
1022
1057
assert_eq ! ( ( -1f32 ) . powf( f32 :: NEG_INFINITY ) , 1f32 ) ;
1023
1058
assert_eq ! ( ( -1f64 ) . powf( f64 :: INFINITY ) , 1f64 ) ;
@@ -1039,11 +1074,6 @@ pub fn libm() {
1039
1074
assert_eq ! ( 10.0f64 . powi( 0 ) , 1.0f64 ) ;
1040
1075
assert_eq ! ( f32 :: INFINITY . powi( 0 ) , 1.0f32 ) ;
1041
1076
assert_eq ! ( f64 :: INFINITY . powi( 0 ) , 1.0f64 ) ;
1042
- // f*::NAN doesn't specify which what kind of bit pattern
1043
- // the NAN will have.
1044
- // We **assume** f*::NAN is not signaling.
1045
- assert_eq ! ( f32 :: NAN . powi( 0 ) , 1.0f32 ) ;
1046
- assert_eq ! ( f64 :: NAN . powi( 0 ) , 1.0f64 ) ;
1047
1077
1048
1078
assert_eq ! ( ( -0f32 ) . powi( 10 ) , 0f32 ) ;
1049
1079
assert_eq ! ( ( -0f64 ) . powi( 100 ) , 0f64 ) ;
0 commit comments