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
23 changes: 3 additions & 20 deletions library/coretests/tests/floats/f128.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
#![cfg(target_has_reliable_f128)]

use super::{assert_approx_eq, assert_biteq};
#[cfg(any(miri, target_has_reliable_f128_math))]
use super::assert_approx_eq;
use super::assert_biteq;

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

Expand Down Expand Up @@ -74,25 +76,6 @@ fn test_float_bits_conv() {
assert_eq!(f128::from_bits(masked_nan2).to_bits(), masked_nan2);
}

#[test]
fn test_algebraic() {
let a: f128 = 123.0;
let b: f128 = 456.0;

// Check that individual operations match their primitive counterparts.
//
// This is a check of current implementations and does NOT imply any form of
// guarantee about future behavior. The compiler reserves the right to make
// these operations inexact matches in the future.
let eps = if cfg!(miri) { 1e-6 } else { 0.0 };

assert_approx_eq!(a.algebraic_add(b), a + b, eps);
assert_approx_eq!(a.algebraic_sub(b), a - b, eps);
assert_approx_eq!(a.algebraic_mul(b), a * b, eps);
assert_approx_eq!(a.algebraic_div(b), a / b, eps);
assert_approx_eq!(a.algebraic_rem(b), a % b, eps);
}

#[test]
fn test_from() {
assert_biteq!(f128::from(false), 0.0);
Expand Down
21 changes: 0 additions & 21 deletions library/coretests/tests/floats/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,6 @@ fn test_float_bits_conv() {
assert_eq!(f16::from_bits(masked_nan2).to_bits(), masked_nan2);
}

#[test]
fn test_algebraic() {
let a: f16 = 123.0;
let b: f16 = 456.0;

// Check that individual operations match their primitive counterparts.
//
// This is a check of current implementations and does NOT imply any form of
// guarantee about future behavior. The compiler reserves the right to make
// these operations inexact matches in the future.
let eps_add = if cfg!(miri) { 1e1 } else { 0.0 };
let eps_mul = if cfg!(miri) { 1e3 } else { 0.0 };
let eps_div = if cfg!(miri) { 1e0 } else { 0.0 };

assert_approx_eq!(a.algebraic_add(b), a + b, eps_add);
assert_approx_eq!(a.algebraic_sub(b), a - b, eps_add);
assert_approx_eq!(a.algebraic_mul(b), a * b, eps_mul);
assert_approx_eq!(a.algebraic_div(b), a / b, eps_div);
assert_approx_eq!(a.algebraic_rem(b), a % b, eps_div);
}

#[test]
fn test_from() {
assert_biteq!(f16::from(false), 0.0);
Expand Down
23 changes: 1 addition & 22 deletions library/coretests/tests/floats/f32.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::f32;

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

/// First pattern over the mantissa
const NAN_MASK1: u32 = 0x002a_aaaa;
Expand Down Expand Up @@ -47,24 +47,3 @@ fn test_float_bits_conv() {
assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);
}

#[test]
fn test_algebraic() {
let a: f32 = 123.0;
let b: f32 = 456.0;

// Check that individual operations match their primitive counterparts.
//
// This is a check of current implementations and does NOT imply any form of
// guarantee about future behavior. The compiler reserves the right to make
// these operations inexact matches in the future.
let eps_add = if cfg!(miri) { 1e-3 } else { 0.0 };
let eps_mul = if cfg!(miri) { 1e-1 } else { 0.0 };
let eps_div = if cfg!(miri) { 1e-4 } else { 0.0 };

assert_approx_eq!(a.algebraic_add(b), a + b, eps_add);
assert_approx_eq!(a.algebraic_sub(b), a - b, eps_add);
assert_approx_eq!(a.algebraic_mul(b), a * b, eps_mul);
assert_approx_eq!(a.algebraic_div(b), a / b, eps_div);
assert_approx_eq!(a.algebraic_rem(b), a % b, eps_div);
}
21 changes: 1 addition & 20 deletions library/coretests/tests/floats/f64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::f64;

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

/// First pattern over the mantissa
const NAN_MASK1: u64 = 0x000a_aaaa_aaaa_aaaa;
Expand Down Expand Up @@ -46,22 +46,3 @@ fn test_float_bits_conv() {
assert_eq!(f64::from_bits(masked_nan1).to_bits(), masked_nan1);
assert_eq!(f64::from_bits(masked_nan2).to_bits(), masked_nan2);
}

#[test]
fn test_algebraic() {
let a: f64 = 123.0;
let b: f64 = 456.0;

// Check that individual operations match their primitive counterparts.
//
// This is a check of current implementations and does NOT imply any form of
// guarantee about future behavior. The compiler reserves the right to make
// these operations inexact matches in the future.
let eps = if cfg!(miri) { 1e-6 } else { 0.0 };

assert_approx_eq!(a.algebraic_add(b), a + b, eps);
assert_approx_eq!(a.algebraic_sub(b), a - b, eps);
assert_approx_eq!(a.algebraic_mul(b), a * b, eps);
assert_approx_eq!(a.algebraic_div(b), a / b, eps);
assert_approx_eq!(a.algebraic_rem(b), a % b, eps);
}
39 changes: 39 additions & 0 deletions library/coretests/tests/floats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ trait TestableFloat: Sized {
const NAN_MASK1: Self::Int;
/// Second pattern over the mantissa
const NAN_MASK2: Self::Int;
const EPS_ADD: Self;
const EPS_MUL: Self;
const EPS_DIV: Self;
}

impl TestableFloat for f16 {
Expand All @@ -44,6 +47,9 @@ impl TestableFloat for f16 {
const MAX_DOWN: Self = Self::from_bits(0x7bfe);
const NAN_MASK1: Self::Int = 0x02aa;
const NAN_MASK2: Self::Int = 0x0155;
const EPS_ADD: Self = if cfg!(miri) { 1e1 } else { 0.0 };
const EPS_MUL: Self = if cfg!(miri) { 1e3 } else { 0.0 };
const EPS_DIV: Self = if cfg!(miri) { 1e0 } else { 0.0 };
}

impl TestableFloat for f32 {
Expand All @@ -63,6 +69,9 @@ impl TestableFloat for f32 {
const MAX_DOWN: Self = Self::from_bits(0x7f7f_fffe);
const NAN_MASK1: Self::Int = 0x002a_aaaa;
const NAN_MASK2: Self::Int = 0x0055_5555;
const EPS_ADD: Self = if cfg!(miri) { 1e-3 } else { 0.0 };
const EPS_MUL: Self = if cfg!(miri) { 1e-1 } else { 0.0 };
const EPS_DIV: Self = if cfg!(miri) { 1e-4 } else { 0.0 };
}

impl TestableFloat for f64 {
Expand All @@ -78,6 +87,9 @@ impl TestableFloat for f64 {
const MAX_DOWN: Self = Self::from_bits(0x7fef_ffff_ffff_fffe);
const NAN_MASK1: Self::Int = 0x000a_aaaa_aaaa_aaaa;
const NAN_MASK2: Self::Int = 0x0005_5555_5555_5555;
const EPS_ADD: Self = if cfg!(miri) { 1e-6 } else { 0.0 };
const EPS_MUL: Self = if cfg!(miri) { 1e-6 } else { 0.0 };
const EPS_DIV: Self = if cfg!(miri) { 1e-6 } else { 0.0 };
}

impl TestableFloat for f128 {
Expand All @@ -93,6 +105,9 @@ impl TestableFloat for f128 {
const MAX_DOWN: Self = Self::from_bits(0x7ffefffffffffffffffffffffffffffe);
const NAN_MASK1: Self::Int = 0x0000aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
const NAN_MASK2: Self::Int = 0x00005555555555555555555555555555;
const EPS_ADD: Self = if cfg!(miri) { 1e-6 } else { 0.0 };
const EPS_MUL: Self = if cfg!(miri) { 1e-6 } else { 0.0 };
const EPS_DIV: Self = if cfg!(miri) { 1e-6 } else { 0.0 };
}

/// Determine the tolerance for values of the argument type.
Expand Down Expand Up @@ -1440,3 +1455,27 @@ float_test! {
assert_biteq!(neg_inf.to_radians(), neg_inf);
}
}

float_test! {
name: to_algebraic,
attrs: {
f16: #[cfg(target_has_reliable_f16)],
f128: #[cfg(target_has_reliable_f128)],
},
test<Float> {
let a: Float = 123.0;
let b: Float = 456.0;

// Check that individual operations match their primitive counterparts.
//
// This is a check of current implementations and does NOT imply any form of
// guarantee about future behavior. The compiler reserves the right to make
// these operations inexact matches in the future.

assert_approx_eq!(a.algebraic_add(b), a + b, Float::EPS_ADD);
assert_approx_eq!(a.algebraic_sub(b), a - b, Float::EPS_ADD);
assert_approx_eq!(a.algebraic_mul(b), a * b, Float::EPS_MUL);
assert_approx_eq!(a.algebraic_div(b), a / b, Float::EPS_DIV);
assert_approx_eq!(a.algebraic_rem(b), a % b, Float::EPS_DIV);
}
}
Loading