Skip to content

Commit

Permalink
fixup! Add a test against musl libm
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Oct 21, 2024
1 parent 9af3e68 commit 7c9a327
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions crates/libm-test/tests/compare_built_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use std::sync::LazyLock;

use libm_test::gen::CachedInput;
use libm_test::musl_allowed_ulp;
use libm_test::{CheckOutput, GenerateInput, TupleCall};
use musl_math_sys as musl;
use rand::{Rng, SeedableRng};
Expand All @@ -40,29 +41,6 @@ const NTESTS: usize = {
ntests
};

/// ULP allowed to differ from musl (note that musl itself may not be accurate).
const ALLOWED_ULP: u32 = 2;

/// Certain functions have different allowed ULP (consider these xfail).
///
/// Currently this includes:
/// - gamma functions that have higher errors
/// - 32-bit functions fall back to a less precise algorithm.
const ULP_OVERRIDES: &[(&str, u32)] = &[
#[cfg(x86_no_sse)]
("asinhf", 6),
("lgamma", 6),
("lgamma_r", 6),
("lgammaf", 6),
("lgammaf_r", 6),
("tanh", 4),
("tgamma", 8),
#[cfg(not(target_pointer_width = "64"))]
("exp10", 4),
#[cfg(not(target_pointer_width = "64"))]
("exp10f", 4),
];

/// Tested inputs.
static TEST_CASES: LazyLock<CachedInput> = LazyLock::new(|| make_test_cases(NTESTS));

Expand Down Expand Up @@ -123,17 +101,14 @@ macro_rules! musl_rand_tests {
&TEST_CASES
};

let ulp = match ULP_OVERRIDES.iter().find(|(name, _val)| name == &fname) {
Some((_name, val)) => *val,
None => ALLOWED_ULP,
};
let ulp = musl_allowed_ulp(fname);

let cases = <CachedInput as GenerateInput<$RustArgs>>::get_cases(inputs);
for input in cases {
let mres = input.call(musl::$fn_name as $CFn);
let cres = input.call(libm::$fn_name as $RustFn);
let musl_res = input.call(musl::$fn_name as $CFn);
let crate_res = input.call(libm::$fn_name as $RustFn);

mres.validate(cres, input, ulp);
musl_res.validate(crate_res, input, ulp).unwrap();
}
}
} };
Expand Down

0 comments on commit 7c9a327

Please sign in to comment.