Skip to content

Commit 8ac2e73

Browse files
committed
Reduce error to 4ULP.
1 parent 3977b3a commit 8ac2e73

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

library/std/tests/floats/f16.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,9 @@ fn test_algebraic() {
961961

962962
assert_approx_eq!(a.algebraic_add(b), a + b, 1e1);
963963
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);
964+
assert_approx_eq!(a.algebraic_mul(b), a * b, 1e2);
965+
assert_approx_eq!(a.algebraic_div(b), a / b, 1e0);
966+
assert_approx_eq!(a.algebraic_rem(b), a % b, 1e0);
967967
}
968968

969969
#[test]

library/std/tests/floats/f32.rs

Lines changed: 4 additions & 4 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, 1e-2);
925-
assert_approx_eq!(a.algebraic_sub(b), a - b, 1e-2);
924+
assert_approx_eq!(a.algebraic_add(b), a + b, 1e-3);
925+
assert_approx_eq!(a.algebraic_sub(b), a - b, 1e-3);
926926
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);
927+
assert_approx_eq!(a.algebraic_div(b), a / b, 1e-4);
928+
assert_approx_eq!(a.algebraic_rem(b), a % b, 1e-4);
929929
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
411411
};
412412
let res = this.binary_op(op, &a, &b)?;
413413
// `binary_op` already called `generate_nan` if needed.
414-
// Apply a relative error of 16ULP to simulate non-deterministic precision loss
414+
// Apply a relative error of 4ULP to simulate non-deterministic precision loss
415415
// due to optimizations.
416-
let res = apply_random_float_error_to_imm(this, res, 4 /* log2(16) */)?;
416+
let res = apply_random_float_error_to_imm(this, res, 2 /* log2(4) */)?;
417417
this.write_immediate(*res, dest)?;
418418
}
419419

@@ -464,9 +464,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
464464
if !float_finite(&res)? {
465465
throw_ub_format!("`{intrinsic_name}` intrinsic produced non-finite value as result");
466466
}
467-
// Apply a relative error of 16ULP to simulate non-deterministic precision loss
467+
// Apply a relative error of 4ULP to simulate non-deterministic precision loss
468468
// due to optimizations.
469-
let res = apply_random_float_error_to_imm(this, res, 4 /* log2(16) */)?;
469+
let res = apply_random_float_error_to_imm(this, res, 2 /* log2(4) */)?;
470470
this.write_immediate(*res, dest)?;
471471
}
472472

0 commit comments

Comments
 (0)