Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit ae3ab74

Browse files
committed
Use approx_eq in unit tests
1 parent 41b817d commit ae3ab74

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

crates/libm-test/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ macro_rules! assert_approx_eq {
151151
panic!(f);
152152
}
153153
};
154+
($result:expr, $expected:expr, ulp: $ulps:expr) => {
155+
if !$crate::WithinUlps::within_ulps($result, $expected, $ulps) {
156+
panic!("{:?} != {:?}", $result, $expected);
157+
}
158+
}
154159
}
155160

156161
pub trait Toward: Sized {

crates/libm-test/tests/unit.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![cfg(test)]
22

33
use libm::*;
4+
use libm_test::assert_approx_eq;
5+
46
#[test]
57
fn remquo_q_overflow() {
68
// 0xc000000000000001, 0x04c0000000000004
@@ -349,14 +351,19 @@ fn y1f_2002() {
349351
fn fma_segfault_bug() {
350352
// An attempt to substract with overflow was causing a segfault
351353
// on FMA for these inputs:
352-
assert_eq!(
354+
assert_approx_eq!(
353355
fma(
354356
-0.0000000000000002220446049250313,
355357
-0.0000000000000002220446049250313,
356358
-0.0000000000000002220446049250313
357359
),
358-
-0.00000000000000022204460492503126
360+
-0.00000000000000022204460492503126,
361+
ulp: 0
359362
);
360363

361-
assert_eq!(fma(-0.992, -0.992, -0.992), -0.00793599999988632);
364+
assert_approx_eq!(
365+
fma(-0.992, -0.992, -0.992),
366+
-0.00793599999988632,
367+
ulp: 0
368+
);
362369
}

0 commit comments

Comments
 (0)