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

Commit 2bd6dbb

Browse files
committed
Add basic infinite precision tests with random input
1 parent d72ae69 commit 2bd6dbb

File tree

8 files changed

+429
-6
lines changed

8 files changed

+429
-6
lines changed

ci/docker/aarch64-unknown-linux-gnu/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ubuntu:24.04
33
RUN apt-get update && \
44
apt-get install -y --no-install-recommends \
55
gcc libc6-dev ca-certificates \
6-
gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
6+
gcc-aarch64-linux-gnu m4 make libc6-dev-arm64-cross \
77
qemu-user-static
88

99
ENV TOOLCHAIN_PREFIX=aarch64-linux-gnu-

ci/docker/i686-unknown-linux-gnu/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM ubuntu:24.04
22

33
RUN apt-get update && \
44
apt-get install -y --no-install-recommends \
5-
gcc-multilib libc6-dev ca-certificates
5+
gcc-multilib m4 make libc6-dev ca-certificates

ci/docker/x86_64-unknown-linux-gnu/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM ubuntu:24.04
22

33
RUN apt-get update && \
44
apt-get install -y --no-install-recommends \
5-
gcc libc6-dev ca-certificates
5+
gcc m4 make libc6-dev ca-certificates

ci/run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ case "$target" in
2424
*thumb*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
2525
esac
2626

27+
# Configure which targets test against MPFR
28+
case "$target" in
29+
# MSVC cannot link MPFR
30+
*windows-msvc*) ;;
31+
# FIXME: MinGW should be able to build MPFR, but setup in CI is nontrivial.
32+
*windows-gnu*) ;;
33+
# Targets that aren't cross compiled work fine
34+
# FIXME(ci): we should be able to enable aarch64 Linux here once GHA
35+
# support rolls out.
36+
x86_64*) extra_flags="$extra_flags --features libm-test/multiprecision-tests" ;;
37+
# i686 works fine, i586 does not
38+
i686*) extra_flags="$extra_flags --features libm-test/multiprecision-tests" ;;
39+
# Apple aarch64 is native
40+
aarch64*apple*) extra_flags="$extra_flags --features libm-test/multiprecision-tests" ;;
41+
esac
42+
2743
# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
2844
# <https://github.com/rust-lang/rust/issues/128944>
2945
case "$target" in

crates/libm-test/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ default = []
1010
# Generate tests which are random inputs and the outputs are calculated with
1111
# musl libc.
1212
musl-bitwise-tests = ["rand"]
13+
multiprecision-tests = ["dep:az", "dep:rug"]
1314

1415
[dependencies]
1516
anyhow = "1.0.90"
17+
az = { version = "1.2.1", optional = true }
1618
libm = { path = "../.." }
1719
libm-macros = { path = "../libm-macros" }
1820
paste = "1.0.15"
1921
rand = "0.8.5"
2022
rand_chacha = "0.3.1"
23+
rug = { version = "1.26.1", optional = true, default-features = false, features = ["float", "std"] }
2124

2225
[target.'cfg(target_family = "wasm")'.dependencies]
2326
# Enable randomness on WASM

crates/libm-test/src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pub mod gen;
2+
#[cfg(feature = "multiprecision-tests")]
3+
pub mod mpfloat;
24
mod num_traits;
35
mod test_traits;
46

@@ -8,15 +10,19 @@ pub use test_traits::{CheckOutput, GenerateInput, TupleCall};
810
// List of all files present in libm's source
911
include!(concat!(env!("OUT_DIR"), "/all_files.rs"));
1012

11-
/// ULP allowed to differ from musl (note that musl itself may not be accurate).
13+
/// Default ULP allowed to differ from musl (note that musl itself may not be accurate).
1214
const MUSL_DEFAULT_ULP: u32 = 2;
1315

14-
/// Certain functions have different allowed ULP (consider these xfail).
16+
/// Default ULP allowed to differ from multiprecision (i.e. infinite) results.
17+
const MULTIPREC_DEFAULT_ULP: u32 = 1;
18+
19+
/// ULP allowed to differ from muls results.
1520
///
16-
/// Currently this includes:
21+
/// Current overrides includes:
1722
/// - gamma functions that have higher errors
1823
/// - 32-bit functions fall back to a less precise algorithm.
1924
pub fn musl_allowed_ulp(name: &str) -> u32 {
25+
// Consider overrides xfail
2026
match name {
2127
#[cfg(x86_no_sse)]
2228
"asinhf" => 6,
@@ -30,3 +36,19 @@ pub fn musl_allowed_ulp(name: &str) -> u32 {
3036
_ => MUSL_DEFAULT_ULP,
3137
}
3238
}
39+
40+
/// ULP allowed to differ from multiprecision results.
41+
pub fn multiprec_allowed_ulp(name: &str) -> u32 {
42+
// Consider overrides xfail
43+
match name {
44+
"asinh" | "asinhf" => 2,
45+
"atanh" | "atanhf" => 2,
46+
"exp10" | "exp10f" => 3,
47+
"j0" | "j0f" => 2,
48+
"lgamma" | "lgammaf" | "lgamma_r" | "lgammaf_r" => 2,
49+
"sinh" | "sinhf" => 2,
50+
"tanh" | "tanhf" => 2,
51+
"tgamma" => 6,
52+
_ => MULTIPREC_DEFAULT_ULP,
53+
}
54+
}

0 commit comments

Comments
 (0)