Skip to content

Commit 550a13b

Browse files
refactor + reword
1 parent 51ebf6c commit 550a13b

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
@@ -529,8 +529,8 @@ fn random_nan<S: Semantics>(rng: &mut StdRng) -> IeeeFloat<S> {
529529
///
530530
/// For `powf*` operations of the form:
531531
///
532-
/// - `x^(±0)` where `x` is a SNaN
533-
/// - `1^y` where `y` is SNaN
532+
/// - `(SNaN)^(±0)`
533+
/// - `1^(SNaN)`
534534
///
535535
/// The result is implementation-defined:
536536
/// - musl returns for both `1.0`
@@ -565,13 +565,9 @@ fn fixed_float_value<S: Semantics>(
565565

566566
// x^(±0) = 1 for any x, even a NaN, *but* not a SNaN
567567
("powf32" | "powf64", [base, exp]) if exp.is_zero() => {
568+
let rng = ecx.machine.rng.get_mut();
568569
// Handle both the musl and glibc cases non-deterministically.
569-
if base.is_signaling() {
570-
let rng = ecx.machine.rng.get_mut();
571-
if rng.random() { one } else { random_nan(rng) }
572-
} else {
573-
one
574-
}
570+
if !base.is_signaling() || rng.random() { one } else { random_nan(rng) }
575571
}
576572

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

583579
/// Returns `Some(output)` if `powi` (called `pown` in C) results in a fixed value specified in the C standard
584580
/// (specifically, C23 annex F.10.4.6) when doing `base^exp`. Otherwise, returns `None`.
585-
// 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.
581+
// 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.
586582
fn fixed_powi_float_value<S: Semantics>(
587583
ecx: &mut MiriInterpCx<'_>,
588584
base: IeeeFloat<S>,

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

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

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

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

0 commit comments

Comments
 (0)