nanvm_lib/vm/number/neg.rs
1use core::ops::Neg;
2
3use crate::vm::Number;
4
5impl Neg for Number {
6 type Output = Self;
7 fn neg(self) -> Self {
8 (-self.0).into()
9 }
10}
11
12#[cfg(test)]
13mod tests {
14 use crate::vm::{Number, number::tests::bits};
15
16 /// `-NaN`, the program the sign flip comes from: `f64`'s negation
17 /// flips the sign bit, and the result is the canonical `NaN` anyway.
18 #[test]
19 fn nan_is_canonical() {
20 assert_eq!(bits(-Number::from(f64::NAN)), bits(Number::NAN));
21 assert_eq!(bits(-Number::from(0.0)), (-0.0f64).to_bits());
22 }
23}