Skip to content

Commit 01a0a3a

Browse files
address review
1 parent 773bccb commit 01a0a3a

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed

library/std/src/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl f32 {
479479
/// // log5(5) - 1 == 0
480480
/// let abs_difference = (five.log(5.0) - 1.0).abs();
481481
///
482-
/// assert!(abs_difference <= 1e-7);
482+
/// assert!(abs_difference <= 1e-6);
483483
/// ```
484484
///
485485
/// Non-positive values:

src/tools/miri/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#![feature(derive_coerce_pointee)]
1919
#![feature(arbitrary_self_types)]
2020
#![feature(iter_advance_by)]
21-
#![feature(f16)]
22-
#![feature(f128)]
2321
// Configure clippy and other lints
2422
#![allow(
2523
clippy::collapsible_else_if,

src/tools/miri/src/math.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::ops::Neg;
2-
use std::{f16, f32, f64, f128};
2+
use std::{f32, f64};
33

44
use rand::Rng as _;
55
use rustc_apfloat::Float as _;
6-
use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, QuadS, Semantics, SingleS};
6+
use rustc_apfloat::ieee::{DoubleS, IeeeFloat, Semantics, SingleS};
77
use rustc_middle::ty::{self, FloatTy, ScalarInt};
88

99
use crate::*;
@@ -427,16 +427,14 @@ macro_rules! impl_ieee_pi {
427427
#[inline]
428428
fn pi() -> Self {
429429
// We take the value from the standard library as the most reasonable source for an exact π here.
430-
Self::from_bits($float_ty::consts::PI.to_bits() as _)
430+
Self::from_bits($float_ty::consts::PI.to_bits().into())
431431
}
432432
}
433433
};
434434
}
435435

436-
impl_ieee_pi!(f16, HalfS);
437436
impl_ieee_pi!(f32, SingleS);
438437
impl_ieee_pi!(f64, DoubleS);
439-
impl_ieee_pi!(f128, QuadS);
440438

441439
#[cfg(test)]
442440
mod tests {

src/tools/miri/src/shims/foreign_items.rs

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
851851
let res = res.to_soft();
852852
// Apply a relative error of 4ULP to introduce some non-determinism
853853
// simulating imprecise implementations and optimizations.
854-
let res = math::apply_random_float_error_ulp(
855-
this, res, 2, // log2(4)
856-
);
854+
let res = math::apply_random_float_error_ulp(this, res, 4);
857855

858856
// Clamp the result to the guaranteed range of this function according to the C standard,
859857
// if any.
@@ -872,27 +870,26 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
872870
let f1 = this.read_scalar(f1)?.to_f32()?;
873871
let f2 = this.read_scalar(f2)?.to_f32()?;
874872

875-
let res = math::fixed_float_value(this, link_name.as_str(), &[f1, f2]).unwrap_or_else(|| {
876-
let res = match link_name.as_str() {
877-
// underscore case for windows, here and below
878-
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
879-
// Using host floats (but it's fine, these operations do not have guaranteed precision).
880-
"_hypotf" | "hypotf" => f1.to_host().hypot(f2.to_host()).to_soft(),
881-
"atan2f" => f1.to_host().atan2(f2.to_host()).to_soft(),
882-
#[allow(deprecated)]
883-
"fdimf" => f1.to_host().abs_sub(f2.to_host()).to_soft(),
884-
_ => bug!(),
885-
};
886-
// Apply a relative error of 4ULP to introduce some non-determinism
887-
// simulating imprecise implementations and optimizations.
888-
let res = math::apply_random_float_error_ulp(
889-
this, res, 2, // log2(4)
890-
);
891-
892-
// Clamp the result to the guaranteed range of this function according to the C standard,
893-
// if any.
894-
math::clamp_float_value(link_name.as_str(), res)
895-
});
873+
let res = math::fixed_float_value(this, link_name.as_str(), &[f1, f2])
874+
.unwrap_or_else(|| {
875+
let res = match link_name.as_str() {
876+
// underscore case for windows, here and below
877+
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
878+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
879+
"_hypotf" | "hypotf" => f1.to_host().hypot(f2.to_host()).to_soft(),
880+
"atan2f" => f1.to_host().atan2(f2.to_host()).to_soft(),
881+
#[allow(deprecated)]
882+
"fdimf" => f1.to_host().abs_sub(f2.to_host()).to_soft(),
883+
_ => bug!(),
884+
};
885+
// Apply a relative error of 4ULP to introduce some non-determinism
886+
// simulating imprecise implementations and optimizations.
887+
let res = math::apply_random_float_error_ulp(this, res, 4);
888+
889+
// Clamp the result to the guaranteed range of this function according to the C standard,
890+
// if any.
891+
math::clamp_float_value(link_name.as_str(), res)
892+
});
896893
let res = this.adjust_nan(res, &[f1, f2]);
897894
this.write_scalar(res, dest)?;
898895
}
@@ -937,9 +934,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
937934
let res = res.to_soft();
938935
// Apply a relative error of 4ULP to introduce some non-determinism
939936
// simulating imprecise implementations and optimizations.
940-
let res = math::apply_random_float_error_ulp(
941-
this, res, 2, // log2(4)
942-
);
937+
let res = math::apply_random_float_error_ulp(this, res, 4);
943938

944939
// Clamp the result to the guaranteed range of this function according to the C standard,
945940
// if any.
@@ -971,9 +966,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
971966
};
972967
// Apply a relative error of 4ULP to introduce some non-determinism
973968
// simulating imprecise implementations and optimizations.
974-
let res = math::apply_random_float_error_ulp(
975-
this, res, 2, // log2(4)
976-
);
969+
let res = math::apply_random_float_error_ulp(this, res, 4);
977970

978971
// Clamp the result to the guaranteed range of this function according to the C standard,
979972
// if any.
@@ -1008,7 +1001,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
10081001
let res = res.to_soft();
10091002
// Apply a relative error of 4ULP to introduce some non-determinism
10101003
// simulating imprecise implementations and optimizations.
1011-
let res = math::apply_random_float_error_ulp(this, res, 2 /* log2(4) */);
1004+
let res = math::apply_random_float_error_ulp(this, res, 4);
10121005
// Clamp the result to the guaranteed range of this function according to the C standard,
10131006
// if any.
10141007
let res = math::clamp_float_value(link_name.as_str(), res);
@@ -1027,7 +1020,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
10271020
let res = res.to_soft();
10281021
// Apply a relative error of 4ULP to introduce some non-determinism
10291022
// simulating imprecise implementations and optimizations.
1030-
let res = math::apply_random_float_error_ulp(this, res, 2 /* log2(4) */);
1023+
let res = math::apply_random_float_error_ulp(this, res, 4);
10311024
// Clamp the result to the guaranteed range of this function according to the C standard,
10321025
// if any.
10331026
let res = math::clamp_float_value(link_name.as_str(), res);

0 commit comments

Comments
 (0)