Skip to content

Commit 8316cec

Browse files
committed
make unary float negation slightly nicer
1 parent 0012af6 commit 8316cec

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/librustc_mir/interpret/operator.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc::mir;
22
use rustc::ty::{self, layout::TyLayout};
33
use syntax::ast::FloatTy;
4-
use rustc_apfloat::ieee::{Double, Single};
54
use rustc_apfloat::Float;
65
use rustc::mir::interpret::{InterpResult, Scalar};
76

@@ -335,13 +334,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
335334
Ok(Scalar::from_bool(res))
336335
}
337336
ty::Float(fty) => {
338-
let val = val.to_bits(layout.size)?;
339337
let res = match (un_op, fty) {
340-
(Neg, FloatTy::F32) => Single::to_bits(-Single::from_bits(val)),
341-
(Neg, FloatTy::F64) => Double::to_bits(-Double::from_bits(val)),
338+
(Neg, FloatTy::F32) => Scalar::from_f32(-val.to_f32()?),
339+
(Neg, FloatTy::F64) => Scalar::from_f64(-val.to_f64()?),
342340
_ => bug!("Invalid float op {:?}", un_op)
343341
};
344-
Ok(Scalar::from_uint(res, layout.size))
342+
Ok(res)
345343
}
346344
_ => {
347345
assert!(layout.ty.is_integral());

0 commit comments

Comments
 (0)