ensure unary minus propagates NaN payloads exactly
This commit is contained in:
parent
6796c5765d
commit
615d738abe
2 changed files with 9 additions and 0 deletions
|
@ -461,6 +461,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
Ok((ImmTy::from_bool(res, *self.tcx), false))
|
Ok((ImmTy::from_bool(res, *self.tcx), false))
|
||||||
}
|
}
|
||||||
ty::Float(fty) => {
|
ty::Float(fty) => {
|
||||||
|
// No NaN adjustment here, `-` is a bitwise operation!
|
||||||
let res = match (un_op, fty) {
|
let res = match (un_op, fty) {
|
||||||
(Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
|
(Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
|
||||||
(Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),
|
(Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),
|
||||||
|
|
|
@ -241,6 +241,14 @@ fn test_f32() {
|
||||||
]),
|
]),
|
||||||
|| F32::from(just1 % all1_snan),
|
|| 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() {
|
fn test_f64() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue