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

Commit d2ab22c

Browse files
committed
First pass at wiring things up
1 parent bf22040 commit d2ab22c

File tree

3 files changed

+120
-26
lines changed

3 files changed

+120
-26
lines changed

crates/libm-test/examples/plot_domains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn plot_one<D: Domain<f32>>(out_dir: &Path, name: &str, j_args: &mut Vec<String>
4646
let f = fs::File::create(&text_file).unwrap();
4747
let mut w = BufWriter::new(f);
4848

49-
for input in domain::get_test_cases::<f32, D>() {
49+
for input in domain::get_test_cases_for_domain::<f32, D>() {
5050
writeln!(w, "{:e}", input.0).unwrap();
5151
}
5252
w.flush().unwrap();

crates/libm-test/src/gen/domain.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use std::ops::Bound;
1515

1616
use libm::support::{Float, MinInt};
1717

18-
use crate::domain::Domain;
19-
use crate::{FloatExt, logspace};
18+
use crate::domain::{Domain, HasDomain};
19+
use crate::{FloatExt, MathOp, logspace};
2020

2121
/// Number of values near an interesting point to check.
2222
const AROUND: usize = 100;
@@ -44,7 +44,16 @@ const NTESTS: usize = {
4444
const MAX_ASYMPTOTES: usize = 10;
4545

4646
/// Create a test case iterator.
47-
pub fn get_test_cases<F: Float, D: Domain<F>>() -> impl Iterator<Item = (F,)>
47+
pub fn get_test_cases<Op>() -> impl Iterator<Item = (Op::FTy,)>
48+
where
49+
Op: MathOp + HasDomain<Op::FTy>,
50+
<Op::FTy as Float>::Int: TryFrom<usize>,
51+
{
52+
get_test_cases_for_domain::<Op::FTy, Op::D>()
53+
}
54+
55+
/// Create test cases given a domain.
56+
pub fn get_test_cases_for_domain<F: Float, D: Domain<F>>() -> impl Iterator<Item = (F,)>
4857
where
4958
F::Int: TryFrom<usize>,
5059
{

crates/libm-test/tests/multiprecision.rs

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
33
#![cfg(feature = "test-multiprecision")]
44

5-
use libm_test::gen::{CachedInput, random};
5+
use libm_test::domain::HasDomain;
6+
use libm_test::gen::{CachedInput, domain, random};
67
use libm_test::mpfloat::MpOp;
7-
use libm_test::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, MathOp, TupleCall};
8+
use libm_test::{CheckBasis, CheckCtx, CheckOutput, Float, GenerateInput, MathOp, TupleCall};
89

910
/// Implement a test against MPFR with random inputs.
1011
macro_rules! multiprec_rand_tests {
@@ -22,6 +23,7 @@ macro_rules! multiprec_rand_tests {
2223
};
2324
}
2425

26+
/// Test a single routine with random inputs
2527
fn test_one_random<Op>()
2628
where
2729
Op: MathOp + MpOp,
@@ -39,37 +41,123 @@ where
3941
}
4042
}
4143

42-
// TODO: wire up
43-
#[expect(unused)]
44+
libm_macros::for_each_function! {
45+
callback: multiprec_rand_tests,
46+
attributes: [
47+
// Also an assertion failure on i686: at `MPFR_ASSERTN (! mpfr_erangeflag_p ())`
48+
#[ignore = "large values are infeasible in MPFR"]
49+
[jn, jnf],
50+
],
51+
skip: [
52+
// FIXME: MPFR tests needed
53+
frexp,
54+
frexpf,
55+
ilogb,
56+
ilogbf,
57+
ldexp,
58+
ldexpf,
59+
modf,
60+
modff,
61+
remquo,
62+
remquof,
63+
scalbn,
64+
scalbnf,
65+
66+
// FIXME: test needed, see
67+
// https://github.com/rust-lang/libm/pull/311#discussion_r1818273392
68+
nextafter,
69+
nextafterf,
70+
],
71+
}
72+
73+
/// Implement a test against MPFR with domain-aware inputs.
74+
macro_rules! multiprec_domain_tests {
75+
(
76+
fn_name: $fn_name:ident,
77+
attrs: [$($meta:meta)*]
78+
) => {
79+
paste::paste! {
80+
#[test]
81+
$(#[$meta])*
82+
fn [< multiprec_domain_ $fn_name >]() {
83+
test_one_domain::<libm_test::op::$fn_name::Routine>();
84+
}
85+
}
86+
};
87+
}
88+
89+
/// Test a single routine against domaine-aware inputs
4490
fn test_one_domain<Op>()
4591
where
46-
Op: MathOp + MpOp,
47-
CachedInput: GenerateInput<Op::RustArgs>,
92+
// Complicated generics...
93+
// The operation must take a single float argument (unary only)
94+
Op: MathOp<RustArgs = (<Op as MathOp>::FTy,)>,
95+
// It must also support multiprecision operations
96+
Op: MpOp,
97+
// And it must have a domain specified
98+
Op: HasDomain<Op::FTy>,
99+
// The single float argument tuple must be able to call the `RustFn` and return `RustRet`
100+
(<Op as MathOp>::FTy,): TupleCall<<Op as MathOp>::RustFn, Output = <Op as MathOp>::RustRet>,
101+
// And then we need to be able to cast integers (required by `Domain`).
102+
<Op::FTy as Float>::Int: TryFrom<usize>,
48103
{
49104
let name = Op::NAME_STR;
50105

51106
let ulp = multiprec_allowed_ulp(name);
52107
let mut mp_vals = Op::new_mp();
53108
let ctx = CheckCtx::new(ulp, name, CheckBasis::Mpfr);
54-
// let cases = random::get_test_cases::<Op::RustArgs>(&ctx);
109+
let cases = domain::get_test_cases::<Op>();
55110

56-
// for input in cases {
57-
// let mp_res = Op::run(&mut mp_vals, input);
58-
// let crate_res = input.call(Op::ROUTINE);
111+
for input in cases {
112+
let mp_res = Op::run(&mut mp_vals, input);
113+
let crate_res = input.call(Op::ROUTINE);
59114

60-
// crate_res.validate(mp_res, input, &ctx).unwrap();
61-
// }
115+
crate_res.validate(mp_res, input, &ctx).unwrap();
116+
}
62117
}
63118

64119
libm_macros::for_each_function! {
65-
callback: multiprec_rand_tests,
66-
attributes: [
67-
// Also an assertion failure on i686: at `MPFR_ASSERTN (! mpfr_erangeflag_p ())`
68-
#[ignore = "large values are infeasible in MPFR"]
69-
[jn, jnf],
70-
],
120+
callback: multiprec_domain_tests,
121+
attributes: [],
71122
skip: [
72-
// FIXME: MPFR tests needed
123+
atan2f,
124+
copysignf,
125+
fdimf,
126+
fmaxf,
127+
fminf,
128+
fmodf,
129+
hypotf,
130+
nextafterf,
131+
powf,
132+
remainderf,
133+
atan2,
134+
copysign,
135+
fdim,
136+
fmax,
137+
fmin,
138+
fmod,
139+
hypot,
140+
nextafter,
141+
pow,
142+
remainder,
143+
fmaf,
144+
fma,
145+
ilogbf,
146+
ilogb,
147+
modf,
148+
modff,
149+
jnf,
150+
jn,
151+
remquo,
152+
remquof,
153+
tgamma,
154+
tgammaf,
155+
lgammaf_r,
156+
lgamma_r,
157+
lgamma,
158+
lgammaf,
159+
sincos,
160+
sincosf,
73161
frexp,
74162
frexpf,
75163
ilogb,
@@ -82,9 +170,6 @@ libm_macros::for_each_function! {
82170
remquof,
83171
scalbn,
84172
scalbnf,
85-
86-
// FIXME: test needed, see
87-
// https://github.com/rust-lang/libm/pull/311#discussion_r1818273392
88173
nextafter,
89174
nextafterf,
90175
],

0 commit comments

Comments
 (0)