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
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/std_float/tests/float.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(portable_simd)]
#![feature(f16)]

macro_rules! unary_test {
{ $scalar:tt, $($func:tt),+ } => {
Expand Down Expand Up @@ -91,5 +92,6 @@ macro_rules! impl_tests {
}
}

impl_tests! { f16 }
impl_tests! { f32 }
impl_tests! { f64 }
1 change: 0 additions & 1 deletion crates/test_helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ publish = false

[dependencies]
proptest = { workspace = true, features = ["alloc", "std"] }
float-cmp = "0.10"
13 changes: 9 additions & 4 deletions crates/test_helpers/src/approxeq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Compare numeric types approximately.

use float_cmp::Ulps;

pub trait ApproxEq {
fn approxeq(&self, other: &Self, _ulps: i64) -> bool;
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result;
Expand Down Expand Up @@ -43,7 +41,14 @@ macro_rules! impl_float_approxeq {
if self.is_nan() && other.is_nan() {
true
} else {
(self.ulps(other) as i64).abs() <= ulps
let allowed_ulp_diff = ulps;

// Approximate the ULP by taking half the distance between the number one place "up"
// and the number one place "down".
let ulp = (other.next_up() - other.next_down()) / 2.0;
let ulp_diff = ((self - other) / ulp).abs().round() as i64;

ulp_diff <= allowed_ulp_diff
}
}

Expand All @@ -55,7 +60,7 @@ macro_rules! impl_float_approxeq {
};
}

impl_float_approxeq! { f32, f64 }
impl_float_approxeq! { f16, f32, f64 }

impl<T: ApproxEq, const N: usize> ApproxEq for [T; N] {
fn approxeq(&self, other: &Self, ulps: i64) -> bool {
Expand Down
Loading