Rollup merge of #77368 - est31:apfloat_fix, r=varkor
Backport LLVM apfloat commit to rustc_apfloat
Backports LLVM commit: e34bd1e0b0
Fixes #69532
This commit is contained in:
commit
9ea462fd70
|
@ -1511,11 +1511,16 @@ impl<S: Semantics, T: Semantics> FloatConvert<IeeeFloat<T>> for IeeeFloat<S> {
|
|||
sig::set_bit(&mut r.sig, T::PRECISION - 1);
|
||||
}
|
||||
|
||||
// gcc forces the Quiet bit on, which means (float)(double)(float_sNan)
|
||||
// does not give you back the same bits. This is dubious, and we
|
||||
// don't currently do it. You're really supposed to get
|
||||
// an invalid operation signal at runtime, but nobody does that.
|
||||
status = Status::OK;
|
||||
// Convert of sNaN creates qNaN and raises an exception (invalid op).
|
||||
// This also guarantees that a sNaN does not become Inf on a truncation
|
||||
// that loses all payload bits.
|
||||
if self.is_signaling() {
|
||||
// Quiet signaling NaN.
|
||||
sig::set_bit(&mut r.sig, T::QNAN_BIT);
|
||||
status = Status::INVALID_OP;
|
||||
} else {
|
||||
status = Status::OK;
|
||||
}
|
||||
} else {
|
||||
*loses_info = false;
|
||||
status = Status::OK;
|
||||
|
|
|
@ -566,6 +566,17 @@ fn fma() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_69532() {
|
||||
let f = Double::from_bits(0x7FF0_0000_0000_0001u64 as u128);
|
||||
let mut loses_info = false;
|
||||
let sta = f.convert(&mut loses_info);
|
||||
let r: Single = sta.value;
|
||||
assert!(loses_info);
|
||||
assert!(r.is_nan());
|
||||
assert_eq!(sta.status, Status::INVALID_OP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn min_num() {
|
||||
let f1 = Double::from_f64(1.0);
|
||||
|
@ -1492,27 +1503,32 @@ fn convert() {
|
|||
assert_eq!(4294967295.0, test.to_f64());
|
||||
assert!(!loses_info);
|
||||
|
||||
let test = Single::snan(None);
|
||||
let x87_snan = X87DoubleExtended::snan(None);
|
||||
let test: X87DoubleExtended = test.convert(&mut loses_info).value;
|
||||
assert!(test.bitwise_eq(x87_snan));
|
||||
assert!(!loses_info);
|
||||
|
||||
let test = Single::qnan(None);
|
||||
let x87_qnan = X87DoubleExtended::qnan(None);
|
||||
let test: X87DoubleExtended = test.convert(&mut loses_info).value;
|
||||
assert!(test.bitwise_eq(x87_qnan));
|
||||
assert!(!loses_info);
|
||||
|
||||
let test = X87DoubleExtended::snan(None);
|
||||
let test: X87DoubleExtended = test.convert(&mut loses_info).value;
|
||||
assert!(test.bitwise_eq(x87_snan));
|
||||
let test = Single::snan(None);
|
||||
let sta = test.convert(&mut loses_info);
|
||||
let test: X87DoubleExtended = sta.value;
|
||||
assert!(test.is_nan());
|
||||
assert!(!test.is_signaling());
|
||||
assert!(!loses_info);
|
||||
assert_eq!(sta.status, Status::INVALID_OP);
|
||||
|
||||
let test = X87DoubleExtended::qnan(None);
|
||||
let test: X87DoubleExtended = test.convert(&mut loses_info).value;
|
||||
assert!(test.bitwise_eq(x87_qnan));
|
||||
assert!(!loses_info);
|
||||
|
||||
let test = X87DoubleExtended::snan(None);
|
||||
let sta = test.convert(&mut loses_info);
|
||||
let test: X87DoubleExtended = sta.value;
|
||||
assert!(test.is_nan());
|
||||
assert!(!test.is_signaling());
|
||||
assert!(!loses_info);
|
||||
assert_eq!(sta.status, Status::INVALID_OP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// run-pass
|
||||
#![feature(const_fn_transmute)]
|
||||
|
||||
const fn make_nans() -> (f64, f64, f32, f32) {
|
||||
let nan1: f64 = unsafe { std::mem::transmute(0x7FF0_0001_0000_0001u64) };
|
||||
let nan2: f64 = unsafe { std::mem::transmute(0x7FF0_0000_0000_0001u64) };
|
||||
|
||||
let nan1_32 = nan1 as f32;
|
||||
let nan2_32 = nan2 as f32;
|
||||
|
||||
(nan1, nan2, nan1_32, nan2_32)
|
||||
}
|
||||
|
||||
static NANS: (f64, f64, f32, f32) = make_nans();
|
||||
|
||||
fn main() {
|
||||
let (nan1, nan2, nan1_32, nan2_32) = NANS;
|
||||
|
||||
assert!(nan1.is_nan());
|
||||
assert!(nan2.is_nan());
|
||||
|
||||
assert!(nan1_32.is_nan());
|
||||
assert!(nan2_32.is_nan());
|
||||
}
|
Loading…
Reference in New Issue