Skip to content

Commit 9028efc

Browse files
committed
dedup to_radians float test
1 parent c81a8a8 commit 9028efc

File tree

5 files changed

+26
-68
lines changed

5 files changed

+26
-68
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f128)]
33

4-
use std::f128::consts;
5-
64
use super::{assert_approx_eq, assert_biteq};
75

86
// Note these tolerances make sense around zero, but not for more extreme exponents.
97

108
/// Default tolerances. Works for values that should be near precise but not exact. Roughly
119
/// the precision carried by `100 * 100`.
10+
#[allow(unused)]
1211
const TOL: f128 = 1e-12;
1312

1413
/// For operations that are near exact, usually not involving math of different
1514
/// signs.
15+
#[allow(unused)]
1616
const TOL_PRECISE: f128 = 1e-28;
1717

1818
/// First pattern over the mantissa
@@ -52,23 +52,6 @@ fn test_max_recip() {
5252
);
5353
}
5454

55-
#[test]
56-
fn test_to_radians() {
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_radians(), 0.0);
62-
assert_approx_eq!(154.6f128.to_radians(), 2.6982790235832334267135442069489767804, TOL);
63-
assert_approx_eq!((-332.31f128).to_radians(), -5.7999036373023566567593094812182763013, TOL);
64-
// check approx rather than exact because round trip for pi doesn't fall on an exactly
65-
// representable value (unlike `f32` and `f64`).
66-
assert_approx_eq!(180.0f128.to_radians(), pi, TOL_PRECISE);
67-
assert!(nan.to_radians().is_nan());
68-
assert_biteq!(inf.to_radians(), inf);
69-
assert_biteq!(neg_inf.to_radians(), neg_inf);
70-
}
71-
7255
#[test]
7356
fn test_float_bits_conv() {
7457
assert_eq!((1f128).to_bits(), 0x3fff0000000000000000000000000000);

library/coretests/tests/floats/f16.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f16)]
33

4-
use std::f16::consts;
5-
64
use super::{assert_approx_eq, assert_biteq};
75

86
/// Tolerance for results on the order of 10.0e-2
@@ -54,21 +52,6 @@ fn test_max_recip() {
5452
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
5553
}
5654

57-
#[test]
58-
fn test_to_radians() {
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_radians(), 0.0);
64-
assert_approx_eq!(154.6f16.to_radians(), 2.698279, TOL_0);
65-
assert_approx_eq!((-332.31f16).to_radians(), -5.799903, TOL_0);
66-
assert_approx_eq!(180.0f16.to_radians(), pi, TOL_0);
67-
assert!(nan.to_radians().is_nan());
68-
assert_biteq!(inf.to_radians(), inf);
69-
assert_biteq!(neg_inf.to_radians(), neg_inf);
70-
}
71-
7255
#[test]
7356
fn test_float_bits_conv() {
7457
assert_eq!((1f16).to_bits(), 0x3c00);

library/coretests/tests/floats/f32.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use core::f32;
2-
use core::f32::consts;
32

43
use super::{assert_approx_eq, assert_biteq};
54

@@ -27,21 +26,6 @@ fn test_mul_add() {
2726
assert_biteq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
2827
}
2928

30-
#[test]
31-
fn test_to_radians() {
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_radians(), 0.0);
37-
assert_approx_eq!(154.6f32.to_radians(), 2.698279);
38-
assert_approx_eq!((-332.31f32).to_radians(), -5.799903);
39-
assert_biteq!(180.0f32.to_radians(), pi);
40-
assert!(nan.to_radians().is_nan());
41-
assert_biteq!(inf.to_radians(), inf);
42-
assert_biteq!(neg_inf.to_radians(), neg_inf);
43-
}
44-
4529
#[test]
4630
fn test_float_bits_conv() {
4731
assert_eq!((1f32).to_bits(), 0x3f800000);

library/coretests/tests/floats/f64.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use core::f64;
2-
use core::f64::consts;
32

43
use super::{assert_approx_eq, assert_biteq};
54

@@ -27,21 +26,6 @@ fn test_mul_add() {
2726
assert_biteq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
2827
}
2928

30-
#[test]
31-
fn test_to_radians() {
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_radians(), 0.0);
37-
assert_approx_eq!(154.6f64.to_radians(), 2.698279);
38-
assert_approx_eq!((-332.31f64).to_radians(), -5.799903);
39-
assert_biteq!(180.0f64.to_radians(), pi);
40-
assert!(nan.to_radians().is_nan());
41-
assert_biteq!(inf.to_radians(), inf);
42-
assert_biteq!(neg_inf.to_radians(), neg_inf);
43-
}
44-
4529
#[test]
4630
fn test_float_bits_conv() {
4731
assert_eq!((1f64).to_bits(), 0x3ff0000000000000);

library/coretests/tests/floats/mod.rs

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

Comments
 (0)