Skip to content

Commit

Permalink
Rollup merge of rust-lang#83018 - oli-obk:float_check, r=davidtwco
Browse files Browse the repository at this point in the history
Reintroduce accidentally deleted assertions.

These were removed in rust-lang#50198
  • Loading branch information
JohnTitor authored Mar 11, 2021
2 parents 5ab8f53 + c69b108 commit 14846d9
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions compiler/rustc_mir_build/src/thir/constant.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_apfloat::Float;
use rustc_ast as ast;
use rustc_middle::mir::interpret::{
Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
Expand Down Expand Up @@ -61,20 +62,40 @@ fn parse_float<'tcx>(num: Symbol, fty: ty::FloatTy, neg: bool) -> Result<ConstVa
use rustc_apfloat::ieee::{Double, Single};
let scalar = match fty {
ty::FloatTy::F32 => {
num.parse::<f32>().map_err(|_| ())?;
let rust_f = num.parse::<f32>().map_err(|_| ())?;
let mut f = num.parse::<Single>().unwrap_or_else(|e| {
panic!("apfloat::ieee::Single failed to parse `{}`: {:?}", num, e)
});
assert!(
u128::from(rust_f.to_bits()) == f.to_bits(),
"apfloat::ieee::Single gave different result for `{}`: \
{}({:#x}) vs Rust's {}({:#x})",
rust_f,
f,
f.to_bits(),
Single::from_bits(rust_f.to_bits().into()),
rust_f.to_bits()
);
if neg {
f = -f;
}
Scalar::from_f32(f)
}
ty::FloatTy::F64 => {
num.parse::<f64>().map_err(|_| ())?;
let rust_f = num.parse::<f64>().map_err(|_| ())?;
let mut f = num.parse::<Double>().unwrap_or_else(|e| {
panic!("apfloat::ieee::Double failed to parse `{}`: {:?}", num, e)
});
assert!(
u128::from(rust_f.to_bits()) == f.to_bits(),
"apfloat::ieee::Double gave different result for `{}`: \
{}({:#x}) vs Rust's {}({:#x})",
rust_f,
f,
f.to_bits(),
Double::from_bits(rust_f.to_bits().into()),
rust_f.to_bits()
);
if neg {
f = -f;
}
Expand Down

0 comments on commit 14846d9

Please sign in to comment.