Skip to content

Commit 22f78b1

Browse files
refactor + reword
1 parent e2d7537 commit 22f78b1

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ fn random_nan<S: Semantics>(rng: &mut StdRng) -> IeeeFloat<S> {
517517
///
518518
/// For `powf*` operations of the form:
519519
///
520-
/// - `x^(±0)` where `x` is a SNaN
521-
/// - `1^y` where `y` is SNaN
520+
/// - `(SNaN)^(±0)`
521+
/// - `1^(SNaN)`
522522
///
523523
/// The result is implementation-defined:
524524
/// - musl returns for both `1.0`
@@ -553,13 +553,9 @@ fn fixed_float_value<S: Semantics>(
553553

554554
// x^(±0) = 1 for any x, even a NaN, *but* not a SNaN
555555
("powf32" | "powf64", [base, exp]) if exp.is_zero() => {
556+
let rng = ecx.machine.rng.get_mut();
556557
// Handle both the musl and glibc cases non-deterministically.
557-
if base.is_signaling() {
558-
let rng = ecx.machine.rng.get_mut();
559-
if rng.random() { one } else { random_nan(rng) }
560-
} else {
561-
one
562-
}
558+
if !base.is_signaling() || rng.random() { one } else { random_nan(rng) }
563559
}
564560

565561
// There are a lot of cases for fixed outputs according to the C Standard, but these are mainly INF or zero
@@ -570,7 +566,7 @@ fn fixed_float_value<S: Semantics>(
570566

571567
/// Returns `Some(output)` if `powi` (called `pown` in C) results in a fixed value specified in the C standard
572568
/// (specifically, C23 annex F.10.4.6) when doing `base^exp`. Otherwise, returns `None`.
573-
// REVIEW: I'm not sure what I should document here about pown(1, SNaN) since musl and glibc do the same and the C standard is explicit here.
569+
// TODO: I'm not sure what I should document here about pown(1, SNaN) since musl and glibc do the same and the C standard is explicit here.
574570
fn fixed_powi_float_value<S: Semantics>(
575571
ecx: &mut MiriInterpCx<'_>,
576572
base: IeeeFloat<S>,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,18 +1071,18 @@ pub fn libm() {
10711071
($pow_op:expr) => {{
10721072
let mut nan_seen = false;
10731073
let mut one_seen = false;
1074-
1074+
10751075
for _ in 0..64 {
10761076
let res = $pow_op;
10771077
nan_seen |= res.is_nan();
10781078
one_seen |= res == 1.0;
10791079

1080-
// speedup test
1080+
// little speedup
10811081
if nan_seen && one_seen { break; };
10821082
}
10831083

10841084
let op_as_str = stringify!($pow_op);
1085-
1085+
10861086
assert!(nan_seen && one_seen, "{} should return both `NaN` or `1.0` randomly", op_as_str);
10871087
}};
10881088
}

0 commit comments

Comments
 (0)