@@ -8,6 +8,8 @@ trait TestableFloat: Sized {
8
8
const APPROX : Self ;
9
9
/// Allow looser tolerance for f32 on miri
10
10
const POWI_APPROX : Self = Self :: APPROX ;
11
+ /// Allow looser tolerance for f16
12
+ const _180_TO_RADIANS_APPROX: Self = Self :: APPROX ;
11
13
/// Allow for looser tolerance for f16
12
14
const PI_TO_DEGREES_APPROX : Self = Self :: APPROX ;
13
15
const ZERO : Self ;
@@ -30,6 +32,7 @@ trait TestableFloat: Sized {
30
32
impl TestableFloat for f16 {
31
33
type Int = u16 ;
32
34
const APPROX : Self = 1e-3 ;
35
+ const _180_TO_RADIANS_APPROX: Self = 1e-2 ;
33
36
const PI_TO_DEGREES_APPROX : Self = 0.125 ;
34
37
const ZERO : Self = 0.0 ;
35
38
const ONE : Self = 1.0 ;
@@ -1416,3 +1419,24 @@ float_test! {
1416
1419
assert_biteq!( ( 1.0 as Float ) . to_degrees( ) , 57.2957795130823208767981548141051703 ) ;
1417
1420
}
1418
1421
}
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