ensure unary minus propagates NaN payloads exactly

This commit is contained in:
Ralf Jung 2023-10-08 20:36:25 +02:00
parent 6796c5765d
commit 615d738abe
2 changed files with 9 additions and 0 deletions

View File

@ -461,6 +461,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok((ImmTy::from_bool(res, *self.tcx), false))
}
ty::Float(fty) => {
// No NaN adjustment here, `-` is a bitwise operation!
let res = match (un_op, fty) {
(Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
(Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),

View File

@ -241,6 +241,14 @@ fn test_f32() {
]),
|| F32::from(just1 % all1_snan),
);
// Unary `-` must preserve payloads exactly.
check_all_outcomes(HashSet::from_iter([F32::nan(Neg, Quiet, all1_payload)]), || {
F32::from(-all1)
});
check_all_outcomes(HashSet::from_iter([F32::nan(Neg, Signaling, all1_payload)]), || {
F32::from(-all1_snan)
});
}
fn test_f64() {