@@ -7,6 +7,8 @@ trait TestableFloat: Sized {
77 /// Set the default tolerance for float comparison based on the type.
88 const APPROX : Self ;
99 // Needed for looser tolerance for f16
10+ const _180_TO_RADIANS_APPROX: Self = Self :: APPROX ;
11+ // Needed for looser tolerance for f16
1012 const PI_TO_DEGREES_APPROX : Self = Self :: APPROX ;
1113 const ZERO : Self ;
1214 const ONE : Self ;
@@ -28,6 +30,7 @@ trait TestableFloat: Sized {
2830impl TestableFloat for f16 {
2931 type Int = u16 ;
3032 const APPROX : Self = 1e-3 ;
33+ const _180_TO_RADIANS_APPROX: Self = 1e-2 ;
3134 const PI_TO_DEGREES_APPROX : Self = 0.125 ;
3235 const ZERO : Self = 0.0 ;
3336 const ONE : Self = 1.0 ;
@@ -1410,3 +1413,24 @@ float_test! {
14101413 assert_biteq!( ( 1.0 as Float ) . to_degrees( ) , 57.2957795130823208767981548141051703 ) ;
14111414 }
14121415}
1416+
1417+ float_test ! {
1418+ name: to_radians,
1419+ attrs: {
1420+ f16: #[ cfg( target_has_reliable_f16) ] ,
1421+ f128: #[ cfg( target_has_reliable_f128) ] ,
1422+ } ,
1423+ test<Float > {
1424+ let pi: Float = Float :: PI ;
1425+ let nan: Float = Float :: NAN ;
1426+ let inf: Float = Float :: INFINITY ;
1427+ let neg_inf: Float = Float :: NEG_INFINITY ;
1428+ assert_biteq!( ( 0.0 as Float ) . to_radians( ) , 0.0 ) ;
1429+ assert_approx_eq!( ( 154.6 as Float ) . to_radians( ) , 2.6982790235832334267135442069489767804 ) ;
1430+ assert_approx_eq!( ( -332.31 as Float ) . to_radians( ) , -5.7999036373023566567593094812182763013 ) ;
1431+ assert_approx_eq!( ( 180.0 as Float ) . to_radians( ) , pi, Float :: _180_TO_RADIANS_APPROX) ;
1432+ assert!( nan. to_radians( ) . is_nan( ) ) ;
1433+ assert_biteq!( inf. to_radians( ) , inf) ;
1434+ assert_biteq!( neg_inf. to_radians( ) , neg_inf) ;
1435+ }
1436+ }
0 commit comments