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

Commit 2ba42ee

Browse files
committed
fixup! Replace HasDomain to enable multi-argument edge case and domain tests
1 parent e930f6f commit 2ba42ee

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

crates/libm-test/src/domain.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ impl<F: Float> Domain<F> {
7878
const STRICTLY_POSITIVE: Self =
7979
Self { start: Bound::Excluded(F::ZERO), end: Bound::Unbounded, check_points: None };
8080

81-
const fn into_prim_f<I>(self) -> EitherPrim<Self, Domain<I>> {
81+
/// Wrap in the float variant of [`EitherPrim`].
82+
const fn into_prim_float<I>(self) -> EitherPrim<Self, Domain<I>> {
8283
EitherPrim::Float(self)
8384
}
8485
}
@@ -89,7 +90,8 @@ impl<I: Int> Domain<I> {
8990
const UNBOUNDED_INT: Self =
9091
Self { start: Bound::Unbounded, end: Bound::Unbounded, check_points: None };
9192

92-
const fn into_prim_i<F>(self) -> EitherPrim<Domain<F>, Self> {
93+
/// Wrap in the int variant of [`EitherPrim`].
94+
const fn into_prim_int<F>(self) -> EitherPrim<Domain<F>, Self> {
9395
EitherPrim::Int(self)
9496
}
9597
}
@@ -99,65 +101,65 @@ impl<F: Float, I: Int> EitherPrim<Domain<F>, Domain<I>> {
99101
/// x ∈ ℝ
100102
const UNBOUNDED1: [Self; 1] =
101103
[Domain { start: Bound::Unbounded, end: Bound::Unbounded, check_points: None }
102-
.into_prim_f()];
104+
.into_prim_float()];
103105

104106
/// {x1, x2} ∈ ℝ
105107
const UNBOUNDED2: [Self; 2] =
106-
[Domain::UNBOUNDED.into_prim_f(), Domain::UNBOUNDED.into_prim_f()];
108+
[Domain::UNBOUNDED.into_prim_float(), Domain::UNBOUNDED.into_prim_float()];
107109

108110
/// {x1, x2, x3} ∈ ℝ
109111
const UNBOUNDED3: [Self; 3] = [
110-
Domain::UNBOUNDED.into_prim_f(),
111-
Domain::UNBOUNDED.into_prim_f(),
112-
Domain::UNBOUNDED.into_prim_f(),
112+
Domain::UNBOUNDED.into_prim_float(),
113+
Domain::UNBOUNDED.into_prim_float(),
114+
Domain::UNBOUNDED.into_prim_float(),
113115
];
114116

115117
/// {x1, x2} ∈ ℝ, one float and one int
116118
const UNBOUNDED_F_I: [Self; 2] =
117-
[Domain::UNBOUNDED.into_prim_f(), Domain::UNBOUNDED_INT.into_prim_i()];
119+
[Domain::UNBOUNDED.into_prim_float(), Domain::UNBOUNDED_INT.into_prim_int()];
118120

119121
/// x ∈ ℝ >= 0
120-
const POSITIVE: [Self; 1] = [Domain::POSITIVE.into_prim_f()];
122+
const POSITIVE: [Self; 1] = [Domain::POSITIVE.into_prim_float()];
121123

122124
/// x ∈ ℝ > 0
123-
const STRICTLY_POSITIVE: [Self; 1] = [Domain::STRICTLY_POSITIVE.into_prim_f()];
125+
const STRICTLY_POSITIVE: [Self; 1] = [Domain::STRICTLY_POSITIVE.into_prim_float()];
124126

125127
/// Used for versions of `asin` and `acos`.
126128
const INVERSE_TRIG_PERIODIC: [Self; 1] = [Domain {
127129
start: Bound::Included(F::NEG_ONE),
128130
end: Bound::Included(F::ONE),
129131
check_points: None,
130132
}
131-
.into_prim_f()];
133+
.into_prim_float()];
132134

133135
/// Domain for `acosh`
134136
const ACOSH: [Self; 1] =
135137
[Domain { start: Bound::Included(F::ONE), end: Bound::Unbounded, check_points: None }
136-
.into_prim_f()];
138+
.into_prim_float()];
137139

138140
/// Domain for `atanh`
139141
const ATANH: [Self; 1] = [Domain {
140142
start: Bound::Excluded(F::NEG_ONE),
141143
end: Bound::Excluded(F::ONE),
142144
check_points: None,
143145
}
144-
.into_prim_f()];
146+
.into_prim_float()];
145147

146148
/// Domain for `sin`, `cos`, and `tan`
147149
const TRIG: [Self; 1] = [Domain {
148-
// TODO
150+
// Trig functions have special behavior at fractions of π.
149151
check_points: Some(|| Box::new([-F::PI, -F::FRAC_PI_2, F::FRAC_PI_2, F::PI].into_iter())),
150152
..Domain::UNBOUNDED
151153
}
152-
.into_prim_f()];
154+
.into_prim_float()];
153155

154156
/// Domain for `log` in various bases
155157
const LOG: [Self; 1] = Self::STRICTLY_POSITIVE;
156158

157159
/// Domain for `log1p` i.e. `log(1 + x)`
158160
const LOG1P: [Self; 1] =
159161
[Domain { start: Bound::Excluded(F::NEG_ONE), end: Bound::Unbounded, check_points: None }
160-
.into_prim_f()];
162+
.into_prim_float()];
161163

162164
/// Domain for `sqrt`
163165
const SQRT: [Self; 1] = Self::POSITIVE;
@@ -177,7 +179,7 @@ impl<F: Float, I: Int> EitherPrim<Domain<F>, Domain<I>> {
177179
// Whether or not gamma is defined for negative numbers is implementation dependent
178180
..Domain::UNBOUNDED
179181
}
180-
.into_prim_f()];
182+
.into_prim_float()];
181183

182184
/// Domain for `loggamma`
183185
const LGAMMA: [Self; 1] = Self::STRICTLY_POSITIVE;
@@ -186,7 +188,7 @@ impl<F: Float, I: Int> EitherPrim<Domain<F>, Domain<I>> {
186188
// FIXME: the domain should provide some sort of "reasonable range" so we don't actually test
187189
// the entire system unbounded.
188190
const BESSEL_N: [Self; 2] =
189-
[Domain::UNBOUNDED_INT.into_prim_i(), Domain::UNBOUNDED.into_prim_f()];
191+
[Domain::UNBOUNDED_INT.into_prim_int(), Domain::UNBOUNDED.into_prim_float()];
190192
}
191193

192194
/// Get the domain for a given function.

crates/libm-test/src/run_cfg.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,16 @@ pub fn check_near_count(ctx: &CheckCtx) -> u64 {
291291
GeneratorKind::EdgeCases,
292292
"check_near_count is intended for edge case tests"
293293
);
294-
if cfg!(optimizations_enabled) { 100 } else { 10 }
294+
if cfg!(optimizations_enabled) {
295+
// Taper based on the number of inputs.
296+
match ctx.input_count() {
297+
1 | 2 => 100,
298+
3 => 50,
299+
x => panic!("unexpected argument count {x}"),
300+
}
301+
} else {
302+
10
303+
}
295304
}
296305

297306
/// Check whether extensive actions should be run or skipped.

0 commit comments

Comments
 (0)