|
| 1 | +use rustc_apfloat::Float; |
1 | 2 | use rustc_ast as ast;
|
2 | 3 | use rustc_middle::mir::interpret::{
|
3 | 4 | Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
|
@@ -61,20 +62,40 @@ fn parse_float<'tcx>(num: Symbol, fty: ty::FloatTy, neg: bool) -> Result<ConstVa
|
61 | 62 | use rustc_apfloat::ieee::{Double, Single};
|
62 | 63 | let scalar = match fty {
|
63 | 64 | ty::FloatTy::F32 => {
|
64 |
| - num.parse::<f32>().map_err(|_| ())?; |
| 65 | + let rust_f = num.parse::<f32>().map_err(|_| ())?; |
65 | 66 | let mut f = num.parse::<Single>().unwrap_or_else(|e| {
|
66 | 67 | panic!("apfloat::ieee::Single failed to parse `{}`: {:?}", num, e)
|
67 | 68 | });
|
| 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 | + ); |
68 | 79 | if neg {
|
69 | 80 | f = -f;
|
70 | 81 | }
|
71 | 82 | Scalar::from_f32(f)
|
72 | 83 | }
|
73 | 84 | ty::FloatTy::F64 => {
|
74 |
| - num.parse::<f64>().map_err(|_| ())?; |
| 85 | + let rust_f = num.parse::<f64>().map_err(|_| ())?; |
75 | 86 | let mut f = num.parse::<Double>().unwrap_or_else(|e| {
|
76 | 87 | panic!("apfloat::ieee::Double failed to parse `{}`: {:?}", num, e)
|
77 | 88 | });
|
| 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 | + ); |
78 | 99 | if neg {
|
79 | 100 | f = -f;
|
80 | 101 | }
|
|
0 commit comments