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

Commit e299027

Browse files
committed
Rename the special_case module to precision and move default ULP
Having the default ULP in lib.rs doesn't make much sense when everything else precision-related is in special_case.rs. Rename `special_case` to `precision` and move the `*_allowed_ulp` functions there.
1 parent 47bfc9b commit e299027

File tree

2 files changed

+55
-55
lines changed

2 files changed

+55
-55
lines changed

crates/libm-test/src/lib.rs

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ pub mod gen;
22
#[cfg(feature = "test-multiprecision")]
33
pub mod mpfloat;
44
mod num_traits;
5-
mod special_case;
5+
mod precision;
66
mod test_traits;
77

88
pub use num_traits::{Float, Hex, Int};
9-
pub use special_case::{MaybeOverride, SpecialCase};
9+
pub use precision::{MaybeOverride, SpecialCase, multiprec_allowed_ulp, musl_allowed_ulp};
1010
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, TupleCall};
1111

1212
/// Result type for tests is usually from `anyhow`. Most times there is no success value to
@@ -16,59 +16,6 @@ pub type TestResult<T = (), E = anyhow::Error> = Result<T, E>;
1616
// List of all files present in libm's source
1717
include!(concat!(env!("OUT_DIR"), "/all_files.rs"));
1818

19-
/// Default ULP allowed to differ from musl (note that musl itself may not be accurate).
20-
const MUSL_DEFAULT_ULP: u32 = 2;
21-
22-
/// Default ULP allowed to differ from multiprecision (i.e. infinite) results.
23-
const MULTIPREC_DEFAULT_ULP: u32 = 1;
24-
25-
/// ULP allowed to differ from muls results.
26-
///
27-
/// Note that these results were obtained using 400,000,000 rounds of random inputs, which
28-
/// is not a value used by default.
29-
pub fn musl_allowed_ulp(name: &str) -> u32 {
30-
// Consider overrides xfail
31-
match name {
32-
#[cfg(x86_no_sse)]
33-
"asinh" | "asinhf" => 6,
34-
"lgamma" | "lgamma_r" | "lgammaf" | "lgammaf_r" => 400,
35-
"tanh" | "tanhf" => 4,
36-
"tgamma" => 20,
37-
"j0" | "j0f" | "j1" | "j1f" => {
38-
// Results seem very target-dependent
39-
if cfg!(target_arch = "x86_64") { 4000 } else { 800_000 }
40-
}
41-
"jn" | "jnf" => 1000,
42-
"sincosf" => 500,
43-
#[cfg(not(target_pointer_width = "64"))]
44-
"exp10" => 4,
45-
#[cfg(not(target_pointer_width = "64"))]
46-
"exp10f" => 4,
47-
_ => MUSL_DEFAULT_ULP,
48-
}
49-
}
50-
51-
/// ULP allowed to differ from multiprecision results.
52-
pub fn multiprec_allowed_ulp(name: &str) -> u32 {
53-
// Consider overrides xfail
54-
match name {
55-
"asinh" | "asinhf" => 2,
56-
"acoshf" => 4,
57-
"atanh" | "atanhf" => 2,
58-
"exp10" | "exp10f" => 3,
59-
"j0" | "j0f" | "j1" | "j1f" => {
60-
// Results seem very target-dependent
61-
if cfg!(target_arch = "x86_64") { 4000 } else { 800_000 }
62-
}
63-
"jn" | "jnf" => 1000,
64-
"lgamma" | "lgammaf" | "lgamma_r" | "lgammaf_r" => 16,
65-
"sinh" | "sinhf" => 2,
66-
"tanh" | "tanhf" => 2,
67-
"tgamma" => 20,
68-
_ => MULTIPREC_DEFAULT_ULP,
69-
}
70-
}
71-
7219
/// Return the unsuffixed version of a function name; e.g. `abs` and `absf` both return `abs`,
7320
/// `lgamma_r` and `lgammaf_r` both return `lgamma_r`.
7421
pub fn canonical_name(name: &str) -> &str {

crates/libm-test/src/special_case.rs renamed to crates/libm-test/src/precision.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,59 @@ use crate::{CheckBasis, CheckCtx, Float, Int, TestResult};
88
/// Type implementing [`IgnoreCase`].
99
pub struct SpecialCase;
1010

11+
/// Default ULP allowed to differ from musl (note that musl itself may not be accurate).
12+
const MUSL_DEFAULT_ULP: u32 = 2;
13+
14+
/// Default ULP allowed to differ from multiprecision (i.e. infinite) results.
15+
const MULTIPREC_DEFAULT_ULP: u32 = 1;
16+
17+
/// ULP allowed to differ from muls results.
18+
///
19+
/// Note that these results were obtained using 400,000,000 rounds of random inputs, which
20+
/// is not a value used by default.
21+
pub fn musl_allowed_ulp(name: &str) -> u32 {
22+
// Consider overrides xfail
23+
match name {
24+
#[cfg(x86_no_sse)]
25+
"asinh" | "asinhf" => 6,
26+
"lgamma" | "lgamma_r" | "lgammaf" | "lgammaf_r" => 400,
27+
"tanh" | "tanhf" => 4,
28+
"tgamma" => 20,
29+
"j0" | "j0f" | "j1" | "j1f" => {
30+
// Results seem very target-dependent
31+
if cfg!(target_arch = "x86_64") { 4000 } else { 800_000 }
32+
}
33+
"jn" | "jnf" => 1000,
34+
"sincosf" => 500,
35+
#[cfg(not(target_pointer_width = "64"))]
36+
"exp10" => 4,
37+
#[cfg(not(target_pointer_width = "64"))]
38+
"exp10f" => 4,
39+
_ => MUSL_DEFAULT_ULP,
40+
}
41+
}
42+
43+
/// ULP allowed to differ from multiprecision results.
44+
pub fn multiprec_allowed_ulp(name: &str) -> u32 {
45+
// Consider overrides xfail
46+
match name {
47+
"asinh" | "asinhf" => 2,
48+
"acoshf" => 4,
49+
"atanh" | "atanhf" => 2,
50+
"exp10" | "exp10f" => 3,
51+
"j0" | "j0f" | "j1" | "j1f" => {
52+
// Results seem very target-dependent
53+
if cfg!(target_arch = "x86_64") { 4000 } else { 800_000 }
54+
}
55+
"jn" | "jnf" => 1000,
56+
"lgamma" | "lgammaf" | "lgamma_r" | "lgammaf_r" => 16,
57+
"sinh" | "sinhf" => 2,
58+
"tanh" | "tanhf" => 2,
59+
"tgamma" => 20,
60+
_ => MULTIPREC_DEFAULT_ULP,
61+
}
62+
}
63+
1164
/// Don't run further validation on this test case.
1265
const SKIP: Option<TestResult> = Some(Ok(()));
1366

0 commit comments

Comments
 (0)