diff options
| author | beetrees <b@beetr.ee> | 2024-04-18 06:43:44 +0100 |
|---|---|---|
| committer | beetrees <b@beetr.ee> | 2024-04-18 06:43:44 +0100 |
| commit | cc12a1b5119b003132a16e83c19642bb6584f2df (patch) | |
| tree | f2a3d17d0b3b176a66a7a7b3a1d85d588a3ae3d0 /compiler | |
| parent | 5260893724057f707fd993dc3a7a050f3fc7be9e (diff) | |
| download | rust-cc12a1b5119b003132a16e83c19642bb6584f2df.tar.gz rust-cc12a1b5119b003132a16e83c19642bb6584f2df.zip | |
Fix negating `f16` and `f128` constants
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index b5d72619a38..36e0c755007 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -1023,7 +1023,13 @@ pub(crate) fn parse_float_into_scalar( let num = num.as_str(); match float_ty { // FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64` - ty::FloatTy::F16 => num.parse::<Half>().ok().map(Scalar::from_f16), + ty::FloatTy::F16 => { + let mut f = num.parse::<Half>().ok()?; + if neg { + f = -f; + } + Some(Scalar::from_f16(f)) + } ty::FloatTy::F32 => { let Ok(rust_f) = num.parse::<f32>() else { return None }; let mut f = num @@ -1071,7 +1077,13 @@ pub(crate) fn parse_float_into_scalar( Some(Scalar::from_f64(f)) } // FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64` - ty::FloatTy::F128 => num.parse::<Quad>().ok().map(Scalar::from_f128), + ty::FloatTy::F128 => { + let mut f = num.parse::<Quad>().ok()?; + if neg { + f = -f; + } + Some(Scalar::from_f128(f)) + } } } |
