@@ -8,6 +8,8 @@ trait TestableFloat: Sized {
88 const APPROX : Self ;
99 /// Allow looser tolerance for f32 on miri
1010 const POWI_APPROX : Self = Self :: APPROX ;
11+ /// Allow looser tolerance for f16
12+ const _180_TO_RADIANS_APPROX: Self = Self :: APPROX ;
1113 /// Allow for looser tolerance for f16
1214 const PI_TO_DEGREES_APPROX : Self = Self :: APPROX ;
1315 const ZERO : Self ;
@@ -30,6 +32,7 @@ trait TestableFloat: Sized {
3032impl TestableFloat for f16 {
3133 type Int = u16 ;
3234 const APPROX : Self = 1e-3 ;
35+ const _180_TO_RADIANS_APPROX: Self = 1e-2 ;
3336 const PI_TO_DEGREES_APPROX : Self = 0.125 ;
3437 const ZERO : Self = 0.0 ;
3538 const ONE : Self = 1.0 ;
@@ -1416,3 +1419,24 @@ float_test! {
14161419 assert_biteq!( ( 1.0 as Float ) . to_degrees( ) , 57.2957795130823208767981548141051703 ) ;
14171420 }
14181421}
1422+
1423+ float_test ! {
1424+ name: to_radians,
1425+ attrs: {
1426+ f16: #[ cfg( target_has_reliable_f16) ] ,
1427+ f128: #[ cfg( target_has_reliable_f128) ] ,
1428+ } ,
1429+ test<Float > {
1430+ let pi: Float = Float :: PI ;
1431+ let nan: Float = Float :: NAN ;
1432+ let inf: Float = Float :: INFINITY ;
1433+ let neg_inf: Float = Float :: NEG_INFINITY ;
1434+ assert_biteq!( ( 0.0 as Float ) . to_radians( ) , 0.0 ) ;
1435+ assert_approx_eq!( ( 154.6 as Float ) . to_radians( ) , 2.6982790235832334267135442069489767804 ) ;
1436+ assert_approx_eq!( ( -332.31 as Float ) . to_radians( ) , -5.7999036373023566567593094812182763013 ) ;
1437+ assert_approx_eq!( ( 180.0 as Float ) . to_radians( ) , pi, Float :: _180_TO_RADIANS_APPROX) ;
1438+ assert!( nan. to_radians( ) . is_nan( ) ) ;
1439+ assert_biteq!( inf. to_radians( ) , inf) ;
1440+ assert_biteq!( neg_inf. to_radians( ) , neg_inf) ;
1441+ }
1442+ }
0 commit comments