slvm/float/
float_32.rs

1use std::fmt;
2use std::fmt::{Display, Formatter};
3use std::hash::{Hash, Hasher};
4
5#[derive(Copy, Clone, Debug)]
6pub struct F32Wrap(pub f32);
7impl Display for F32Wrap {
8    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
9        write!(f, "{}", self.0)
10    }
11}
12impl From<F32Wrap> for f32 {
13    fn from(f: F32Wrap) -> Self {
14        f.0
15    }
16}
17impl From<f32> for F32Wrap {
18    fn from(f: f32) -> Self {
19        F32Wrap(f)
20    }
21}
22impl From<f64> for F32Wrap {
23    fn from(f: f64) -> Self {
24        F32Wrap(f as f32)
25    }
26}
27impl From<F32Wrap> for f64 {
28    fn from(f: F32Wrap) -> Self {
29        f.0 as f64
30    }
31}
32impl PartialEq for F32Wrap {
33    fn eq(&self, other: &Self) -> bool {
34        self.0 == other.0
35    }
36}
37
38impl Eq for F32Wrap {}
39
40impl Hash for F32Wrap {
41    fn hash<H: Hasher>(&self, state: &mut H) {
42        state.write_u32(self.0.to_bits());
43    }
44}