Skip to main content

nanvm_lib/vm/any/
neg.rs

1use core::ops::Neg;
2
3use crate::vm::{Any, IVm, Unpacked};
4
5impl<A: IVm> Neg for Any<A> {
6    type Output = Result<Any<A>, Any<A>>;
7    fn neg(self) -> Self::Output {
8        // https://tc39.es/ecma262/#sec-unary-minus-operator
9        Ok(Unpacked::from(-self.to_numeric()?).into())
10    }
11}
12
13#[cfg(test)]
14mod test {
15
16    #[test]
17    fn test_neg_zero() {
18        let z = 0.0f64;
19        let nz = -z;
20        assert_ne!(z.to_bits(), nz.to_bits());
21    }
22}