2
2
3
3
#![ cfg( feature = "test-multiprecision" ) ]
4
4
5
- use libm_test:: gen:: { CachedInput , random} ;
5
+ use libm_test:: domain:: HasDomain ;
6
+ use libm_test:: gen:: { CachedInput , domain, random} ;
6
7
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 } ;
8
9
9
10
/// Implement a test against MPFR with random inputs.
10
11
macro_rules! multiprec_rand_tests {
@@ -22,6 +23,7 @@ macro_rules! multiprec_rand_tests {
22
23
} ;
23
24
}
24
25
26
+ /// Test a single routine with random inputs
25
27
fn test_one_random < Op > ( )
26
28
where
27
29
Op : MathOp + MpOp ,
@@ -39,37 +41,123 @@ where
39
41
}
40
42
}
41
43
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
44
90
fn test_one_domain < Op > ( )
45
91
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 > ,
48
103
{
49
104
let name = Op :: NAME_STR ;
50
105
51
106
let ulp = multiprec_allowed_ulp ( name) ;
52
107
let mut mp_vals = Op :: new_mp ( ) ;
53
108
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 > ( ) ;
55
110
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 ) ;
59
114
60
- // crate_res.validate(mp_res, input, &ctx).unwrap();
61
- // }
115
+ crate_res. validate ( mp_res, input, & ctx) . unwrap ( ) ;
116
+ }
62
117
}
63
118
64
119
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: [ ] ,
71
122
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,
73
161
frexp,
74
162
frexpf,
75
163
ilogb,
@@ -82,9 +170,6 @@ libm_macros::for_each_function! {
82
170
remquof,
83
171
scalbn,
84
172
scalbnf,
85
-
86
- // FIXME: test needed, see
87
- // https://github.com/rust-lang/libm/pull/311#discussion_r1818273392
88
173
nextafter,
89
174
nextafterf,
90
175
] ,
0 commit comments