swf_types/
float_is.rs

1pub trait Is {
2  fn is(&self, other: &Self) -> bool;
3}
4
5impl Is for f32 {
6  fn is(&self, other: &f32) -> bool {
7    self.to_bits() == other.to_bits()
8  }
9}
10
11impl Is for f64 {
12  fn is(&self, other: &f64) -> bool {
13    self.to_bits() == other.to_bits()
14  }
15}
16
17impl<T: Is> Is for Vec<T> {
18  fn is(&self, other: &Self) -> bool {
19    if self.len() != other.len() {
20      return false;
21    }
22    for (i, left) in self.iter().enumerate() {
23      if !left.is(&other[i]) {
24        return false;
25      }
26    }
27    true
28  }
29}
30
31impl Is for [f32; 20] {
32  fn is(&self, other: &Self) -> bool {
33    for i in 0..20 {
34      if !self[i].is(&other[i]) {
35        return false;
36      }
37    }
38    true
39  }
40}
41
42#[cfg(test)]
43mod test_float_is {
44  use super::Is;
45
46  #[test]
47  fn test_f32_is() {
48    assert!(::std::f32::NAN.is(&::std::f32::NAN))
49  }
50}