Skip to content

Commit b67dbfa

Browse files
apply simple requests from reviewer
1 parent 6274c4e commit b67dbfa

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/tools/miri/src/intrinsics/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
263263
2, // log2(4)
264264
);
265265

266+
// Clamp the result to the guaranteed range of this function according to the C standard,
267+
// if any.
266268
match intrinsic_name {
267269
// sin and cos: [-1, 1]
268270
"sinf32" | "cosf32" => res.clamp(Single::one().neg(), Single::one()),
@@ -311,7 +313,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
311313
2, // log2(4)
312314
);
313315

314-
// Clamp values to the output range defined in IEEE 754 9.1.
316+
// Clamp the result to the guaranteed range of this function according to the C standard,
317+
// if any.
315318
match intrinsic_name {
316319
// sin and cos: [-1, 1]
317320
"sinf64" | "cosf64" => res.clamp(Double::one().neg(), Double::one()),
@@ -383,8 +386,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
383386
let f2 = this.read_scalar(f2)?.to_f32()?;
384387

385388
let fixed_res = match (f1.category(), f2.category()) {
386-
// 1^y = 1 for any y even a NaN.
387-
// TODO: C Standard says any NaN, IEEE says not a Signaling NaN
389+
// 1^y = 1 for any y, even a NaN.
388390
(Category::Normal, _) if f1 == 1.0f32.to_soft() => Some(1.0f32.to_soft()),
389391

390392
// (-1)^(±INF) = 1
@@ -415,7 +417,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
415417

416418
let fixed_res = match (f1.category(), f2.category()) {
417419
// 1^y = 1 for any y even a NaN.
418-
// TODO: C says any NaN, IEEE says no a Sign NaN
419420
(Category::Normal, _) if f1 == 1.0f64.to_soft() => Some(1.0f64.to_soft()),
420421

421422
// (-1)^(±INF) = 1
@@ -649,11 +650,10 @@ fn fixed_float_value<S: Semantics>(
649650
where
650651
IeeeFloat<S>: std::cmp::PartialEq,
651652
{
652-
// TODO: Should we really fix to ±0? Applying an error has no effect.
653653
let one = IeeeFloat::<S>::one();
654654
match intrinsic_name {
655-
"sinf32" | "sinf64" if input.is_pos_zero() => Some(IeeeFloat::<S>::ZERO),
656-
"sinf32" | "sinf64" if input.is_neg_zero() => Some(-IeeeFloat::<S>::ZERO),
655+
// sin(+- 0) = +- 0.
656+
"sinf32" | "sinf64" if input.is_zero() => Some(input),
657657
"cosf32" | "cosf64" if input.is_zero() => Some(one),
658658
"expf32" | "expf64" | "exp2f32" | "exp2f64" if input.is_zero() => Some(one),
659659
#[rustfmt::skip]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! assert_approx_eq {
3939

4040
($a:expr, $b: expr) => {
4141
// accept up to 52ULP (16ULP for host floats, 4ULP for miri artificial error and 32 for any rounding errors)
42-
assert_approx_eq!($a, $b, 52);
42+
assert_approx_eq!($a, $b, 32);
4343
};
4444
}
4545

@@ -1093,8 +1093,8 @@ pub fn libm() {
10931093
assert_approx_eq!(2.0f32.asinh(), 1.443635475178810342493276740273105f32);
10941094
assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64);
10951095

1096-
// from #4207
1097-
// TODO: should this be the behaviour? I haven't found anything in the IEEE Standard
1096+
// Ensure `sin` always returns something that is a valid input for `asin`, and same for
1097+
// `cos` and `acos`
10981098
let halve_pi_single = std::f32::consts::FRAC_PI_2;
10991099
let halve_pi_double = std::f64::consts::FRAC_PI_2;
11001100
let pi_single = std::f32::consts::PI;

0 commit comments

Comments
 (0)