Skip to content

Commit 3977b3a

Browse files
committed
Restore apply_random_float_error_ulp() and relax error bounds
1 parent c298402 commit 3977b3a

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

library/std/tests/floats/f16.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,11 @@ fn test_algebraic() {
959959
let a: f16 = 123.0;
960960
let b: f16 = 456.0;
961961

962-
assert_approx_eq!(a.algebraic_add(b), a + b);
963-
assert_approx_eq!(a.algebraic_sub(b), a - b);
964-
assert_approx_eq!(a.algebraic_mul(b), a * b);
965-
assert_approx_eq!(a.algebraic_div(b), a / b);
966-
assert_approx_eq!(a.algebraic_rem(b), a % b);
962+
assert_approx_eq!(a.algebraic_add(b), a + b, 1e1);
963+
assert_approx_eq!(a.algebraic_sub(b), a - b, 1e1);
964+
assert_approx_eq!(a.algebraic_mul(b), a * b, 1e3);
965+
assert_approx_eq!(a.algebraic_div(b), a / b, 1e-2);
966+
assert_approx_eq!(a.algebraic_rem(b), a % b, 1e1);
967967
}
968968

969969
#[test]

library/std/tests/floats/f32.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,9 @@ fn test_algebraic() {
921921
let a: f32 = 123.0;
922922
let b: f32 = 456.0;
923923

924-
assert_approx_eq!(a.algebraic_add(b), a + b);
925-
assert_approx_eq!(a.algebraic_sub(b), a - b);
926-
assert_approx_eq!(a.algebraic_mul(b), a * b);
927-
assert_approx_eq!(a.algebraic_div(b), a / b);
928-
assert_approx_eq!(a.algebraic_rem(b), a % b);
924+
assert_approx_eq!(a.algebraic_add(b), a + b, 1e-2);
925+
assert_approx_eq!(a.algebraic_sub(b), a - b, 1e-2);
926+
assert_approx_eq!(a.algebraic_mul(b), a * b, 1e-1);
927+
assert_approx_eq!(a.algebraic_div(b), a / b, 1e-5);
928+
assert_approx_eq!(a.algebraic_rem(b), a % b, 1e-2);
929929
}

src/tools/miri/src/math.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,16 @@ pub(crate) fn apply_random_float_error<F: rustc_apfloat::Float>(
3131
/// This function implements these instructions such that applying a 2^N ULP error is less error prone.
3232
/// So for a 2^N ULP error, you would pass N as the `ulp_exponent` argument.
3333
pub(crate) fn apply_random_float_error_ulp<F: rustc_apfloat::Float>(
34-
_ecx: &mut crate::MiriInterpCx<'_>,
34+
ecx: &mut crate::MiriInterpCx<'_>,
3535
val: F,
36-
_ulp_exponent: u32,
36+
ulp_exponent: u32,
3737
) -> F {
38-
val
39-
// TODO: Re-enable after reducing errors and updating tests. Background:
40-
// https://github.com/rust-lang/rust/pull/136457#discussion_r2019904691
41-
//
42-
// let n = i32::try_from(ulp_exponent)
43-
// .expect("`err_scale_for_ulp`: exponent is too large to create an error scale");
44-
// // we know this fits
45-
// let prec = i32::try_from(F::PRECISION).unwrap();
46-
// let err_scale = -(prec - n - 1);
47-
// apply_random_float_error(ecx, val, err_scale)
38+
let n = i32::try_from(ulp_exponent)
39+
.expect("`err_scale_for_ulp`: exponent is too large to create an error scale");
40+
// we know this fits
41+
let prec = i32::try_from(F::PRECISION).unwrap();
42+
let err_scale = -(prec - n - 1);
43+
apply_random_float_error(ecx, val, err_scale)
4844
}
4945

5046
pub(crate) fn sqrt<S: rustc_apfloat::ieee::Semantics>(x: IeeeFloat<S>) -> IeeeFloat<S> {

0 commit comments

Comments
 (0)