@@ -8,8 +8,11 @@ trait TestableFloat: Sized {
88 const APPROX : Self ;
99 /// Allow looser tolerance for f32 on miri
1010 const POWI_APPROX : Self = Self :: APPROX ;
11+ /// Allow for looser tolerance for f16
12+ const PI_TO_DEGREES_APPROX : Self = Self :: APPROX ;
1113 const ZERO : Self ;
1214 const ONE : Self ;
15+ const PI : Self ;
1316 const MIN_POSITIVE_NORMAL : Self ;
1417 const MAX_SUBNORMAL : Self ;
1518 /// Smallest number
@@ -27,8 +30,10 @@ trait TestableFloat: Sized {
2730impl TestableFloat for f16 {
2831 type Int = u16 ;
2932 const APPROX : Self = 1e-3 ;
33+ const PI_TO_DEGREES_APPROX : Self = 0.125 ;
3034 const ZERO : Self = 0.0 ;
3135 const ONE : Self = 1.0 ;
36+ const PI : Self = std:: f16:: consts:: PI ;
3237 const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
3338 const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
3439 const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -47,6 +52,7 @@ impl TestableFloat for f32 {
4752 const POWI_APPROX : Self = if cfg ! ( miri) { 1e-4 } else { Self :: APPROX } ;
4853 const ZERO : Self = 0.0 ;
4954 const ONE : Self = 1.0 ;
55+ const PI : Self = std:: f32:: consts:: PI ;
5056 const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
5157 const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
5258 const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -61,6 +67,7 @@ impl TestableFloat for f64 {
6167 const APPROX : Self = 1e-6 ;
6268 const ZERO : Self = 0.0 ;
6369 const ONE : Self = 1.0 ;
70+ const PI : Self = std:: f64:: consts:: PI ;
6471 const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
6572 const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
6673 const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -75,6 +82,7 @@ impl TestableFloat for f128 {
7582 const APPROX : Self = 1e-9 ;
7683 const ZERO : Self = 0.0 ;
7784 const ONE : Self = 1.0 ;
85+ const PI : Self = std:: f128:: consts:: PI ;
7886 const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
7987 const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
8088 const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -1387,3 +1395,24 @@ float_test! {
13871395 assert_biteq!( neg_inf. powi( 2 ) , inf) ;
13881396 }
13891397}
1398+
1399+ float_test ! {
1400+ name: to_degrees,
1401+ attrs: {
1402+ f16: #[ cfg( target_has_reliable_f16) ] ,
1403+ f128: #[ cfg( target_has_reliable_f128) ] ,
1404+ } ,
1405+ test<Float > {
1406+ let pi: Float = Float :: PI ;
1407+ let nan: Float = Float :: NAN ;
1408+ let inf: Float = Float :: INFINITY ;
1409+ let neg_inf: Float = Float :: NEG_INFINITY ;
1410+ assert_biteq!( ( 0.0 as Float ) . to_degrees( ) , 0.0 ) ;
1411+ assert_approx_eq!( ( -5.8 as Float ) . to_degrees( ) , -332.31552117587745090765431723855668471 ) ;
1412+ assert_approx_eq!( pi. to_degrees( ) , 180.0 , Float :: PI_TO_DEGREES_APPROX ) ;
1413+ assert!( nan. to_degrees( ) . is_nan( ) ) ;
1414+ assert_biteq!( inf. to_degrees( ) , inf) ;
1415+ assert_biteq!( neg_inf. to_degrees( ) , neg_inf) ;
1416+ assert_biteq!( ( 1.0 as Float ) . to_degrees( ) , 57.2957795130823208767981548141051703 ) ;
1417+ }
1418+ }
0 commit comments