Skip to content

Commit 8f1b338

Browse files
address review
1 parent 3f63265 commit 8f1b338

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ where
227227
let one = IeeeFloat::<S>::one();
228228
let two = IeeeFloat::<S>::two();
229229
let pi = IeeeFloat::<S>::pi();
230-
let pi_over_2 = IeeeFloat::<S>::frac_pi_2();
230+
let pi_over_2 = (pi / two).value;
231231

232-
// Exclusive ranges are made using next_up/next_down.
233232
match intrinsic_name {
234233
// sin, cos, tanh: [-1, 1]
235234
#[rustfmt::skip]
@@ -254,20 +253,17 @@ where
254253
"asinf" | "asin" => val.clamp(pi.neg(), pi),
255254

256255
// atan: (-π/2, +π/2)
257-
"atanf" | "atan" => val.clamp(pi_over_2.neg().next_up().value, pi_over_2.next_down().value),
256+
"atanf" | "atan" => val.clamp(pi_over_2.neg(), pi_over_2),
258257

259258
// erfc: (-1, 1)
260-
"erff" | "erf" => val.clamp(one.neg().next_up().value, one.next_down().value),
259+
"erff" | "erf" => val.clamp(one.neg(), one),
261260

262261
// erfc: (0, 2)
263-
"erfcf" | "erfc" => val.clamp(zero.next_up().value, two.next_down().value),
262+
"erfcf" | "erfc" => val.clamp(zero, two),
264263

265264
// atan2(y, x): arctan(y/x) in [−π, +π]
266265
"atan2f" | "atan2" => val.clamp(pi.neg(), pi),
267266

268-
// FIXME: According to Wolfram Alpha, the range of ln(gamma) is [-0.121486, +INF]. What to do?
269-
"lgammaf_r" | "lgamma_r" => val,
270-
271267
_ => val,
272268
}
273269
}
@@ -1323,12 +1319,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
13231319
IeeeFloat<S>: IeeeExt,
13241320
{
13251321
let this = self.eval_context_mut();
1326-
let zero = IeeeFloat::<S>::ZERO;
13271322
let one = IeeeFloat::<S>::one();
1323+
let two = IeeeFloat::<S>::two();
13281324
let three = IeeeFloat::<S>::three();
13291325
let pi = IeeeFloat::<S>::pi();
1330-
let pi_over_2 = IeeeFloat::<S>::frac_pi_2();
1331-
let pi_over_4 = IeeeFloat::<S>::frac_pi_4();
1326+
let pi_over_2 = (pi / two).value;
1327+
let pi_over_4 = (pi_over_2 / two).value;
13321328

13331329
Some(match (intrinsic_name, args) {
13341330
// cos(±0) and cosh(±0)= 1
@@ -1349,11 +1345,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
13491345
// erfc(-INF) = 2
13501346
("erfcf" | "erfc", [input]) if input.is_neg_infinity() => (one + one).value,
13511347

1352-
// erfc(+INF) = 0
1353-
// REVIEW/HELP: for some reason the tests fail because erfc(+INF) = 1e-45. Which is weird because
1354-
// no error can be applied to 0. Checked and this does not happen without Miri.
1355-
("erfcf" | "erfc", [input]) if input.is_pos_infinity() => zero,
1356-
13571348
// hypot(x, ±0) = abs(x), if x is not a NaN.
13581349
("_hypotf" | "hypotf" | "_hypot" | "hypot", [x, y]) if !x.is_nan() && y.is_zero() =>
13591350
x.abs(),

src/tools/miri/src/math.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,9 @@ pub trait IeeeExt: rustc_apfloat::Float {
176176
Self::from_u128(3).value
177177
}
178178

179-
// Some PI values we use:
180-
181179
/// Equal PI.
182180
fn pi() -> Self;
183181

184-
/// Equal to PI/2.
185-
fn frac_pi_2() -> Self;
186-
187-
/// Equal to PI/4.
188-
fn frac_pi_4() -> Self;
189-
190182
#[inline]
191183
fn clamp(self, min: Self, max: Self) -> Self {
192184
self.maximum(min).minimum(max)
@@ -200,15 +192,6 @@ macro_rules! impl_ieee_pi {
200192
fn pi() -> Self {
201193
Self::from_bits($float_ty::consts::PI.to_bits() as _)
202194
}
203-
#[inline]
204-
fn frac_pi_2() -> Self {
205-
Self::from_bits($float_ty::consts::FRAC_PI_2.to_bits() as _)
206-
}
207-
208-
#[inline]
209-
fn frac_pi_4() -> Self {
210-
Self::from_bits($float_ty::consts::FRAC_PI_4.to_bits() as _)
211-
}
212195
}
213196
};
214197
}

src/tools/miri/tests/pass/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,8 @@ pub fn libm() {
12201220
assert_eq!($float_type::atan2(NEG_INFINITY, 1.0), -FRAC_PI_2, "atan2(-∞, y) returns -π/2 for finite y");
12211221

12221222
// atan2(±∞, −∞) = ±3π/4
1223-
// assert_eq!($float_type::atan2(INFINITY, NEG_INFINITY), 3.0 * FRAC_PI_4, "atan2(+∞, −∞) = 3π/4");
1224-
// assert_eq!($float_type::atan2(NEG_INFINITY, NEG_INFINITY), -3.0 * FRAC_PI_4, "atan2(-∞, −∞) = -3π/4");
1223+
assert_eq!($float_type::atan2(INFINITY, NEG_INFINITY), 3.0 * FRAC_PI_4, "atan2(+∞, −∞) = 3π/4");
1224+
assert_eq!($float_type::atan2(NEG_INFINITY, NEG_INFINITY), -3.0 * FRAC_PI_4, "atan2(-∞, −∞) = -3π/4");
12251225

12261226
// atan2(±∞, +∞) = ±π/4
12271227
assert_eq!($float_type::atan2(INFINITY, INFINITY), FRAC_PI_4, "atan2(+∞, +∞) = π/4");

0 commit comments

Comments
 (0)