Skip to main content

nanvm_lib/vm/number/
sub.rs

1use core::ops::Sub;
2
3use crate::vm::Number;
4
5impl Sub for Number {
6    type Output = Self;
7    fn sub(self, rhs: Self) -> Self {
8        (self.0 - rhs.0).into()
9    }
10}
11
12#[cfg(test)]
13mod tests {
14    use crate::vm::{Number, number::tests::bits};
15
16    /// `Infinity - Infinity` is a `NaN` the hardware made, and it comes out canonical.
17    #[test]
18    fn nan_is_canonical() {
19        let inf = Number::from(f64::INFINITY);
20        assert_eq!(bits(inf - inf), bits(Number::NAN));
21    }
22}