dedup to_degrees float test
This commit is contained in:
parent
e10e6d78ac
commit
c81a8a89ee
5 changed files with 29 additions and 59 deletions
|
|
@ -52,21 +52,6 @@ fn test_max_recip() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_degrees() {
|
||||
let pi: f128 = consts::PI;
|
||||
let nan: f128 = f128::NAN;
|
||||
let inf: f128 = f128::INFINITY;
|
||||
let neg_inf: f128 = f128::NEG_INFINITY;
|
||||
assert_biteq!(0.0f128.to_degrees(), 0.0);
|
||||
assert_approx_eq!((-5.8f128).to_degrees(), -332.31552117587745090765431723855668471, TOL);
|
||||
assert_approx_eq!(pi.to_degrees(), 180.0, TOL);
|
||||
assert!(nan.to_degrees().is_nan());
|
||||
assert_biteq!(inf.to_degrees(), inf);
|
||||
assert_biteq!(neg_inf.to_degrees(), neg_inf);
|
||||
assert_biteq!(1_f128.to_degrees(), 57.2957795130823208767981548141051703);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_radians() {
|
||||
let pi: f128 = consts::PI;
|
||||
|
|
|
|||
|
|
@ -54,21 +54,6 @@ fn test_max_recip() {
|
|||
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_degrees() {
|
||||
let pi: f16 = consts::PI;
|
||||
let nan: f16 = f16::NAN;
|
||||
let inf: f16 = f16::INFINITY;
|
||||
let neg_inf: f16 = f16::NEG_INFINITY;
|
||||
assert_biteq!(0.0f16.to_degrees(), 0.0);
|
||||
assert_approx_eq!((-5.8f16).to_degrees(), -332.315521, TOL_P2);
|
||||
assert_approx_eq!(pi.to_degrees(), 180.0, TOL_P2);
|
||||
assert!(nan.to_degrees().is_nan());
|
||||
assert_biteq!(inf.to_degrees(), inf);
|
||||
assert_biteq!(neg_inf.to_degrees(), neg_inf);
|
||||
assert_biteq!(1_f16.to_degrees(), 57.2957795130823208767981548141051703);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_radians() {
|
||||
let pi: f16 = consts::PI;
|
||||
|
|
|
|||
|
|
@ -27,21 +27,6 @@ fn test_mul_add() {
|
|||
assert_biteq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_degrees() {
|
||||
let pi: f32 = consts::PI;
|
||||
let nan: f32 = f32::NAN;
|
||||
let inf: f32 = f32::INFINITY;
|
||||
let neg_inf: f32 = f32::NEG_INFINITY;
|
||||
assert_biteq!(0.0f32.to_degrees(), 0.0);
|
||||
assert_approx_eq!((-5.8f32).to_degrees(), -332.315521);
|
||||
assert_biteq!(pi.to_degrees(), 180.0);
|
||||
assert!(nan.to_degrees().is_nan());
|
||||
assert_biteq!(inf.to_degrees(), inf);
|
||||
assert_biteq!(neg_inf.to_degrees(), neg_inf);
|
||||
assert_biteq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_radians() {
|
||||
let pi: f32 = consts::PI;
|
||||
|
|
|
|||
|
|
@ -27,20 +27,6 @@ fn test_mul_add() {
|
|||
assert_biteq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_degrees() {
|
||||
let pi: f64 = consts::PI;
|
||||
let nan: f64 = f64::NAN;
|
||||
let inf: f64 = f64::INFINITY;
|
||||
let neg_inf: f64 = f64::NEG_INFINITY;
|
||||
assert_biteq!(0.0f64.to_degrees(), 0.0);
|
||||
assert_approx_eq!((-5.8f64).to_degrees(), -332.315521);
|
||||
assert_biteq!(pi.to_degrees(), 180.0);
|
||||
assert!(nan.to_degrees().is_nan());
|
||||
assert_biteq!(inf.to_degrees(), inf);
|
||||
assert_biteq!(neg_inf.to_degrees(), neg_inf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_radians() {
|
||||
let pi: f64 = consts::PI;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,11 @@ trait TestableFloat: Sized {
|
|||
const APPROX: Self;
|
||||
/// Allow looser tolerance for f32 on miri
|
||||
const POWI_APPROX: Self = Self::APPROX;
|
||||
/// Allow for looser tolerance for f16
|
||||
const PI_TO_DEGREES_APPROX: Self = Self::APPROX;
|
||||
const ZERO: Self;
|
||||
const ONE: Self;
|
||||
const PI: Self;
|
||||
const MIN_POSITIVE_NORMAL: Self;
|
||||
const MAX_SUBNORMAL: Self;
|
||||
/// Smallest number
|
||||
|
|
@ -27,8 +30,10 @@ trait TestableFloat: Sized {
|
|||
impl TestableFloat for f16 {
|
||||
type Int = u16;
|
||||
const APPROX: Self = 1e-3;
|
||||
const PI_TO_DEGREES_APPROX: Self = 0.125;
|
||||
const ZERO: Self = 0.0;
|
||||
const ONE: Self = 1.0;
|
||||
const PI: Self = std::f16::consts::PI;
|
||||
const MIN_POSITIVE_NORMAL: Self = Self::MIN_POSITIVE;
|
||||
const MAX_SUBNORMAL: Self = Self::MIN_POSITIVE.next_down();
|
||||
const TINY: Self = Self::from_bits(0x1);
|
||||
|
|
@ -47,6 +52,7 @@ impl TestableFloat for f32 {
|
|||
const POWI_APPROX: Self = if cfg!(miri) { 1e-4 } else { Self::APPROX };
|
||||
const ZERO: Self = 0.0;
|
||||
const ONE: Self = 1.0;
|
||||
const PI: Self = std::f32::consts::PI;
|
||||
const MIN_POSITIVE_NORMAL: Self = Self::MIN_POSITIVE;
|
||||
const MAX_SUBNORMAL: Self = Self::MIN_POSITIVE.next_down();
|
||||
const TINY: Self = Self::from_bits(0x1);
|
||||
|
|
@ -61,6 +67,7 @@ impl TestableFloat for f64 {
|
|||
const APPROX: Self = 1e-6;
|
||||
const ZERO: Self = 0.0;
|
||||
const ONE: Self = 1.0;
|
||||
const PI: Self = std::f64::consts::PI;
|
||||
const MIN_POSITIVE_NORMAL: Self = Self::MIN_POSITIVE;
|
||||
const MAX_SUBNORMAL: Self = Self::MIN_POSITIVE.next_down();
|
||||
const TINY: Self = Self::from_bits(0x1);
|
||||
|
|
@ -75,6 +82,7 @@ impl TestableFloat for f128 {
|
|||
const APPROX: Self = 1e-9;
|
||||
const ZERO: Self = 0.0;
|
||||
const ONE: Self = 1.0;
|
||||
const PI: Self = std::f128::consts::PI;
|
||||
const MIN_POSITIVE_NORMAL: Self = Self::MIN_POSITIVE;
|
||||
const MAX_SUBNORMAL: Self = Self::MIN_POSITIVE.next_down();
|
||||
const TINY: Self = Self::from_bits(0x1);
|
||||
|
|
@ -1387,3 +1395,24 @@ float_test! {
|
|||
assert_biteq!(neg_inf.powi(2), inf);
|
||||
}
|
||||
}
|
||||
|
||||
float_test! {
|
||||
name: to_degrees,
|
||||
attrs: {
|
||||
f16: #[cfg(target_has_reliable_f16)],
|
||||
f128: #[cfg(target_has_reliable_f128)],
|
||||
},
|
||||
test<Float> {
|
||||
let pi: Float = Float::PI;
|
||||
let nan: Float = Float::NAN;
|
||||
let inf: Float = Float::INFINITY;
|
||||
let neg_inf: Float = Float::NEG_INFINITY;
|
||||
assert_biteq!((0.0 as Float).to_degrees(), 0.0);
|
||||
assert_approx_eq!((-5.8 as Float).to_degrees(), -332.31552117587745090765431723855668471);
|
||||
assert_approx_eq!(pi.to_degrees(), 180.0, Float::PI_TO_DEGREES_APPROX);
|
||||
assert!(nan.to_degrees().is_nan());
|
||||
assert_biteq!(inf.to_degrees(), inf);
|
||||
assert_biteq!(neg_inf.to_degrees(), neg_inf);
|
||||
assert_biteq!((1.0 as Float).to_degrees(), 57.2957795130823208767981548141051703);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue