Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 3 additions & 61 deletions library/coretests/tests/floats/f128.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
#![cfg(target_has_reliable_f128)]

use std::f128::consts;

use super::{assert_approx_eq, assert_biteq};

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

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

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

/// First pattern over the mantissa
Expand Down Expand Up @@ -44,70 +44,12 @@ fn test_mul_add() {

#[test]
#[cfg(any(miri, target_has_reliable_f128_math))]
fn test_recip() {
let nan: f128 = f128::NAN;
let inf: f128 = f128::INFINITY;
let neg_inf: f128 = f128::NEG_INFINITY;
assert_biteq!(1.0f128.recip(), 1.0);
assert_biteq!(2.0f128.recip(), 0.5);
assert_biteq!((-0.4f128).recip(), -2.5);
assert_biteq!(0.0f128.recip(), inf);
fn test_max_recip() {
assert_approx_eq!(
f128::MAX.recip(),
8.40525785778023376565669454330438228902076605e-4933,
1e-4900
);
assert!(nan.recip().is_nan());
assert_biteq!(inf.recip(), 0.0);
assert_biteq!(neg_inf.recip(), -0.0);
}

#[test]
#[cfg(not(miri))]
#[cfg(target_has_reliable_f128_math)]
fn test_powi() {
let nan: f128 = f128::NAN;
let inf: f128 = f128::INFINITY;
let neg_inf: f128 = f128::NEG_INFINITY;
assert_biteq!(1.0f128.powi(1), 1.0);
assert_approx_eq!((-3.1f128).powi(2), 9.6100000000000005506706202140776519387, TOL);
assert_approx_eq!(5.9f128.powi(-2), 0.028727377190462507313100483690639638451, TOL);
assert_biteq!(8.3f128.powi(0), 1.0);
assert!(nan.powi(2).is_nan());
assert_biteq!(inf.powi(3), inf);
assert_biteq!(neg_inf.powi(2), inf);
}

#[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;
let nan: f128 = f128::NAN;
let inf: f128 = f128::INFINITY;
let neg_inf: f128 = f128::NEG_INFINITY;
assert_biteq!(0.0f128.to_radians(), 0.0);
assert_approx_eq!(154.6f128.to_radians(), 2.6982790235832334267135442069489767804, TOL);
assert_approx_eq!((-332.31f128).to_radians(), -5.7999036373023566567593094812182763013, TOL);
// check approx rather than exact because round trip for pi doesn't fall on an exactly
// representable value (unlike `f32` and `f64`).
assert_approx_eq!(180.0f128.to_radians(), pi, TOL_PRECISE);
assert!(nan.to_radians().is_nan());
assert_biteq!(inf.to_radians(), inf);
assert_biteq!(neg_inf.to_radians(), neg_inf);
}

#[test]
Expand Down
60 changes: 1 addition & 59 deletions library/coretests/tests/floats/f16.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
#![cfg(target_has_reliable_f16)]

use std::f16::consts;

use super::{assert_approx_eq, assert_biteq};

/// Tolerance for results on the order of 10.0e-2
Expand Down Expand Up @@ -50,64 +48,8 @@ fn test_mul_add() {

#[test]
#[cfg(any(miri, target_has_reliable_f16_math))]
fn test_recip() {
let nan: f16 = f16::NAN;
let inf: f16 = f16::INFINITY;
let neg_inf: f16 = f16::NEG_INFINITY;
assert_biteq!(1.0f16.recip(), 1.0);
assert_biteq!(2.0f16.recip(), 0.5);
assert_biteq!((-0.4f16).recip(), -2.5);
assert_biteq!(0.0f16.recip(), inf);
fn test_max_recip() {
assert_approx_eq!(f16::MAX.recip(), 1.526624e-5f16, 1e-4);
assert!(nan.recip().is_nan());
assert_biteq!(inf.recip(), 0.0);
assert_biteq!(neg_inf.recip(), -0.0);
}

#[test]
#[cfg(not(miri))]
#[cfg(target_has_reliable_f16_math)]
fn test_powi() {
let nan: f16 = f16::NAN;
let inf: f16 = f16::INFINITY;
let neg_inf: f16 = f16::NEG_INFINITY;
assert_biteq!(1.0f16.powi(1), 1.0);
assert_approx_eq!((-3.1f16).powi(2), 9.61, TOL_0);
assert_approx_eq!(5.9f16.powi(-2), 0.028727, TOL_N2);
assert_biteq!(8.3f16.powi(0), 1.0);
assert!(nan.powi(2).is_nan());
assert_biteq!(inf.powi(3), inf);
assert_biteq!(neg_inf.powi(2), inf);
}

#[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;
let nan: f16 = f16::NAN;
let inf: f16 = f16::INFINITY;
let neg_inf: f16 = f16::NEG_INFINITY;
assert_biteq!(0.0f16.to_radians(), 0.0);
assert_approx_eq!(154.6f16.to_radians(), 2.698279, TOL_0);
assert_approx_eq!((-332.31f16).to_radians(), -5.799903, TOL_0);
assert_approx_eq!(180.0f16.to_radians(), pi, TOL_0);
assert!(nan.to_radians().is_nan());
assert_biteq!(inf.to_radians(), inf);
assert_biteq!(neg_inf.to_radians(), neg_inf);
}

#[test]
Expand Down
64 changes: 0 additions & 64 deletions library/coretests/tests/floats/f32.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::f32;
use core::f32::consts;

use super::{assert_approx_eq, assert_biteq};

Expand All @@ -9,11 +8,6 @@ const NAN_MASK1: u32 = 0x002a_aaaa;
/// Second pattern over the mantissa
const NAN_MASK2: u32 = 0x0055_5555;

/// Miri adds some extra errors to float functions; make sure the tests still pass.
/// These values are purely used as a canary to test against and are thus not a stable guarantee Rust provides.
/// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
const APPROX_DELTA: f32 = if cfg!(miri) { 1e-4 } else { 1e-6 };

// FIXME(#140515): mingw has an incorrect fma https://sourceforge.net/p/mingw-w64/bugs/848/
#[cfg_attr(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")), ignore)]
#[test]
Expand All @@ -32,64 +26,6 @@ fn test_mul_add() {
assert_biteq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
}

#[test]
fn test_recip() {
let nan: f32 = f32::NAN;
let inf: f32 = f32::INFINITY;
let neg_inf: f32 = f32::NEG_INFINITY;
assert_biteq!(1.0f32.recip(), 1.0);
assert_biteq!(2.0f32.recip(), 0.5);
assert_biteq!((-0.4f32).recip(), -2.5);
assert_biteq!(0.0f32.recip(), inf);
assert!(nan.recip().is_nan());
assert_biteq!(inf.recip(), 0.0);
assert_biteq!(neg_inf.recip(), -0.0);
}

#[test]
fn test_powi() {
let nan: f32 = f32::NAN;
let inf: f32 = f32::INFINITY;
let neg_inf: f32 = f32::NEG_INFINITY;
assert_approx_eq!(1.0f32.powi(1), 1.0);
assert_approx_eq!((-3.1f32).powi(2), 9.61, APPROX_DELTA);
assert_approx_eq!(5.9f32.powi(-2), 0.028727);
assert_biteq!(8.3f32.powi(0), 1.0);
assert!(nan.powi(2).is_nan());
assert_biteq!(inf.powi(3), inf);
assert_biteq!(neg_inf.powi(2), 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;
let nan: f32 = f32::NAN;
let inf: f32 = f32::INFINITY;
let neg_inf: f32 = f32::NEG_INFINITY;
assert_biteq!(0.0f32.to_radians(), 0.0);
assert_approx_eq!(154.6f32.to_radians(), 2.698279);
assert_approx_eq!((-332.31f32).to_radians(), -5.799903);
assert_biteq!(180.0f32.to_radians(), pi);
assert!(nan.to_radians().is_nan());
assert_biteq!(inf.to_radians(), inf);
assert_biteq!(neg_inf.to_radians(), neg_inf);
}

#[test]
fn test_float_bits_conv() {
assert_eq!((1f32).to_bits(), 0x3f800000);
Expand Down
58 changes: 0 additions & 58 deletions library/coretests/tests/floats/f64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::f64;
use core::f64::consts;

use super::{assert_approx_eq, assert_biteq};

Expand Down Expand Up @@ -27,63 +26,6 @@ fn test_mul_add() {
assert_biteq!((-3.2f64).mul_add(2.4, neg_inf), neg_inf);
}

#[test]
fn test_recip() {
let nan: f64 = f64::NAN;
let inf: f64 = f64::INFINITY;
let neg_inf: f64 = f64::NEG_INFINITY;
assert_biteq!(1.0f64.recip(), 1.0);
assert_biteq!(2.0f64.recip(), 0.5);
assert_biteq!((-0.4f64).recip(), -2.5);
assert_biteq!(0.0f64.recip(), inf);
assert!(nan.recip().is_nan());
assert_biteq!(inf.recip(), 0.0);
assert_biteq!(neg_inf.recip(), -0.0);
}

#[test]
fn test_powi() {
let nan: f64 = f64::NAN;
let inf: f64 = f64::INFINITY;
let neg_inf: f64 = f64::NEG_INFINITY;
assert_approx_eq!(1.0f64.powi(1), 1.0);
assert_approx_eq!((-3.1f64).powi(2), 9.61);
assert_approx_eq!(5.9f64.powi(-2), 0.028727);
assert_biteq!(8.3f64.powi(0), 1.0);
assert!(nan.powi(2).is_nan());
assert_biteq!(inf.powi(3), inf);
assert_biteq!(neg_inf.powi(2), 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;
let nan: f64 = f64::NAN;
let inf: f64 = f64::INFINITY;
let neg_inf: f64 = f64::NEG_INFINITY;
assert_biteq!(0.0f64.to_radians(), 0.0);
assert_approx_eq!(154.6f64.to_radians(), 2.698279);
assert_approx_eq!((-332.31f64).to_radians(), -5.799903);
assert_biteq!(180.0f64.to_radians(), pi);
assert!(nan.to_radians().is_nan());
assert_biteq!(inf.to_radians(), inf);
assert_biteq!(neg_inf.to_radians(), neg_inf);
}

#[test]
fn test_float_bits_conv() {
assert_eq!((1f64).to_bits(), 0x3ff0000000000000);
Expand Down
Loading
Loading