@@ -8,8 +8,11 @@ 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 for looser tolerance for f16
12
+ const PI_TO_DEGREES_APPROX : Self = Self :: APPROX ;
11
13
const ZERO : Self ;
12
14
const ONE : Self ;
15
+ const PI : Self ;
13
16
const MIN_POSITIVE_NORMAL : Self ;
14
17
const MAX_SUBNORMAL : Self ;
15
18
/// Smallest number
@@ -27,8 +30,10 @@ trait TestableFloat: Sized {
27
30
impl TestableFloat for f16 {
28
31
type Int = u16 ;
29
32
const APPROX : Self = 1e-3 ;
33
+ const PI_TO_DEGREES_APPROX : Self = 0.125 ;
30
34
const ZERO : Self = 0.0 ;
31
35
const ONE : Self = 1.0 ;
36
+ const PI : Self = std:: f16:: consts:: PI ;
32
37
const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
33
38
const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
34
39
const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -47,6 +52,7 @@ impl TestableFloat for f32 {
47
52
const POWI_APPROX : Self = if cfg ! ( miri) { 1e-4 } else { Self :: APPROX } ;
48
53
const ZERO : Self = 0.0 ;
49
54
const ONE : Self = 1.0 ;
55
+ const PI : Self = std:: f32:: consts:: PI ;
50
56
const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
51
57
const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
52
58
const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -61,6 +67,7 @@ impl TestableFloat for f64 {
61
67
const APPROX : Self = 1e-6 ;
62
68
const ZERO : Self = 0.0 ;
63
69
const ONE : Self = 1.0 ;
70
+ const PI : Self = std:: f64:: consts:: PI ;
64
71
const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
65
72
const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
66
73
const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -75,6 +82,7 @@ impl TestableFloat for f128 {
75
82
const APPROX : Self = 1e-9 ;
76
83
const ZERO : Self = 0.0 ;
77
84
const ONE : Self = 1.0 ;
85
+ const PI : Self = std:: f128:: consts:: PI ;
78
86
const MIN_POSITIVE_NORMAL : Self = Self :: MIN_POSITIVE ;
79
87
const MAX_SUBNORMAL : Self = Self :: MIN_POSITIVE . next_down ( ) ;
80
88
const TINY : Self = Self :: from_bits ( 0x1 ) ;
@@ -1387,3 +1395,24 @@ float_test! {
1387
1395
assert_biteq!( neg_inf. powi( 2 ) , inf) ;
1388
1396
}
1389
1397
}
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