mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Fix negating f16
and f128
constants
This commit is contained in:
parent
5260893724
commit
cc12a1b511
@ -1023,7 +1023,13 @@ pub(crate) fn parse_float_into_scalar(
|
|||||||
let num = num.as_str();
|
let num = num.as_str();
|
||||||
match float_ty {
|
match float_ty {
|
||||||
// FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64`
|
// 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 => {
|
ty::FloatTy::F32 => {
|
||||||
let Ok(rust_f) = num.parse::<f32>() else { return None };
|
let Ok(rust_f) = num.parse::<f32>() else { return None };
|
||||||
let mut f = num
|
let mut f = num
|
||||||
@ -1071,7 +1077,13 @@ pub(crate) fn parse_float_into_scalar(
|
|||||||
Some(Scalar::from_f64(f))
|
Some(Scalar::from_f64(f))
|
||||||
}
|
}
|
||||||
// FIXME(f16_f128): When available, compare to the library parser as with `f32` and `f64`
|
// 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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
tests/ui/numbers-arithmetic/f16-f128-lit.rs
Normal file
16
tests/ui/numbers-arithmetic/f16-f128-lit.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//@ run-pass
|
||||||
|
|
||||||
|
#![feature(f16)]
|
||||||
|
#![feature(f128)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(0.0_f16.to_bits(), 0x0000);
|
||||||
|
assert_eq!((-0.0_f16).to_bits(), 0x8000);
|
||||||
|
assert_eq!(10.0_f16.to_bits(), 0x4900);
|
||||||
|
assert_eq!((-10.0_f16).to_bits(), 0xC900);
|
||||||
|
|
||||||
|
assert_eq!(0.0_f128.to_bits(), 0x0000_0000_0000_0000_0000_0000_0000_0000);
|
||||||
|
assert_eq!((-0.0_f128).to_bits(), 0x8000_0000_0000_0000_0000_0000_0000_0000);
|
||||||
|
assert_eq!(10.0_f128.to_bits(), 0x4002_4000_0000_0000_0000_0000_0000_0000);
|
||||||
|
assert_eq!((-10.0_f128).to_bits(), 0xC002_4000_0000_0000_0000_0000_0000_0000);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user