Skip to content

Commit d7b7d9a

Browse files
authored
Rollup merge of rust-lang#83018 - oli-obk:float_check, r=davidtwco
Reintroduce accidentally deleted assertions. These were removed in rust-lang#50198
2 parents 8f20ff6 + c69b108 commit d7b7d9a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

compiler/rustc_mir_build/src/thir/constant.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_apfloat::Float;
12
use rustc_ast as ast;
23
use rustc_middle::mir::interpret::{
34
Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
@@ -61,20 +62,40 @@ fn parse_float<'tcx>(num: Symbol, fty: ty::FloatTy, neg: bool) -> Result<ConstVa
6162
use rustc_apfloat::ieee::{Double, Single};
6263
let scalar = match fty {
6364
ty::FloatTy::F32 => {
64-
num.parse::<f32>().map_err(|_| ())?;
65+
let rust_f = num.parse::<f32>().map_err(|_| ())?;
6566
let mut f = num.parse::<Single>().unwrap_or_else(|e| {
6667
panic!("apfloat::ieee::Single failed to parse `{}`: {:?}", num, e)
6768
});
69+
assert!(
70+
u128::from(rust_f.to_bits()) == f.to_bits(),
71+
"apfloat::ieee::Single gave different result for `{}`: \
72+
{}({:#x}) vs Rust's {}({:#x})",
73+
rust_f,
74+
f,
75+
f.to_bits(),
76+
Single::from_bits(rust_f.to_bits().into()),
77+
rust_f.to_bits()
78+
);
6879
if neg {
6980
f = -f;
7081
}
7182
Scalar::from_f32(f)
7283
}
7384
ty::FloatTy::F64 => {
74-
num.parse::<f64>().map_err(|_| ())?;
85+
let rust_f = num.parse::<f64>().map_err(|_| ())?;
7586
let mut f = num.parse::<Double>().unwrap_or_else(|e| {
7687
panic!("apfloat::ieee::Double failed to parse `{}`: {:?}", num, e)
7788
});
89+
assert!(
90+
u128::from(rust_f.to_bits()) == f.to_bits(),
91+
"apfloat::ieee::Double gave different result for `{}`: \
92+
{}({:#x}) vs Rust's {}({:#x})",
93+
rust_f,
94+
f,
95+
f.to_bits(),
96+
Double::from_bits(rust_f.to_bits().into()),
97+
rust_f.to_bits()
98+
);
7899
if neg {
79100
f = -f;
80101
}

0 commit comments

Comments
 (0)