Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c81a8a8

Browse files
dedup to_degrees float test
1 parent e10e6d7 commit c81a8a8

File tree

5 files changed

+29
-59
lines changed

5 files changed

+29
-59
lines changed

‎library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ fn test_max_recip() {
5252
);
5353
}
5454

55-
#[test]
56-
fn test_to_degrees() {
57-
let pi: f128 = consts::PI;
58-
let nan: f128 = f128::NAN;
59-
let inf: f128 = f128::INFINITY;
60-
let neg_inf: f128 = f128::NEG_INFINITY;
61-
assert_biteq!(0.0f128.to_degrees(), 0.0);
62-
assert_approx_eq!((-5.8f128).to_degrees(), -332.31552117587745090765431723855668471, TOL);
63-
assert_approx_eq!(pi.to_degrees(), 180.0, TOL);
64-
assert!(nan.to_degrees().is_nan());
65-
assert_biteq!(inf.to_degrees(), inf);
66-
assert_biteq!(neg_inf.to_degrees(), neg_inf);
67-
assert_biteq!(1_f128.to_degrees(), 57.2957795130823208767981548141051703);
68-
}
69-
7055
#[test]
7156
fn test_to_radians() {
7257
let pi: f128 = consts::PI;

‎library/coretests/tests/floats/f16.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ fn test_max_recip() {
5454
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
5555
}
5656

57-
#[test]
58-
fn test_to_degrees() {
59-
let pi: f16 = consts::PI;
60-
let nan: f16 = f16::NAN;
61-
let inf: f16 = f16::INFINITY;
62-
let neg_inf: f16 = f16::NEG_INFINITY;
63-
assert_biteq!(0.0f16.to_degrees(), 0.0);
64-
assert_approx_eq!((-5.8f16).to_degrees(), -332.315521, TOL_P2);
65-
assert_approx_eq!(pi.to_degrees(), 180.0, TOL_P2);
66-
assert!(nan.to_degrees().is_nan());
67-
assert_biteq!(inf.to_degrees(), inf);
68-
assert_biteq!(neg_inf.to_degrees(), neg_inf);
69-
assert_biteq!(1_f16.to_degrees(), 57.2957795130823208767981548141051703);
70-
}
71-
7257
#[test]
7358
fn test_to_radians() {
7459
let pi: f16 = consts::PI;

‎library/coretests/tests/floats/f32.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ fn test_mul_add() {
2727
assert_biteq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
2828
}
2929

30-
#[test]
31-
fn test_to_degrees() {
32-
let pi: f32 = consts::PI;
33-
let nan: f32 = f32::NAN;
34-
let inf: f32 = f32::INFINITY;
35-
let neg_inf: f32 = f32::NEG_INFINITY;
36-
assert_biteq!(0.0f32.to_degrees(), 0.0);
37-
assert_approx_eq!((-5.8f32).to_degrees(), -332.315521);
38-
assert_biteq!(pi.to_degrees(), 180.0);
39-
assert!(nan.to_degrees().is_nan());
40-
assert_biteq!(inf.to_degrees(), inf);
41-
assert_biteq!(neg_inf.to_degrees(), neg_inf);
42-
assert_biteq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
43-
}
44-
4530
#[test]
4631
fn test_to_radians() {
4732
let pi: f32 = consts::PI;

‎library/coretests/tests/floats/f64.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@ fn test_mul_add() {
2727
assert_biteq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
2828
}
2929

30-
#[test]
31-
fn test_to_degrees() {
32-
let pi: f64 = consts::PI;
33-
let nan: f64 = f64::NAN;
34-
let inf: f64 = f64::INFINITY;
35-
let neg_inf: f64 = f64::NEG_INFINITY;
36-
assert_biteq!(0.0f64.to_degrees(), 0.0);
37-
assert_approx_eq!((-5.8f64).to_degrees(), -332.315521);
38-
assert_biteq!(pi.to_degrees(), 180.0);
39-
assert!(nan.to_degrees().is_nan());
40-
assert_biteq!(inf.to_degrees(), inf);
41-
assert_biteq!(neg_inf.to_degrees(), neg_inf);
42-
}
43-
4430
#[test]
4531
fn test_to_radians() {
4632
let pi: f64 = consts::PI;

‎library/coretests/tests/floats/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
2730
impl 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /