1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use std::hash::Hasher;

// This is an f32 that supports Hash and Eq. Generally this is dangerous, but here we're
// not doing any sort of fp-arithmetic and not expecting NaN. We should be deterministically
// parsing a string and creating a float from it.
#[derive(Debug, Copy, Clone, Default)]
pub struct DecimalF32(pub f32);

impl Into<f32> for DecimalF32 {
    fn into(self) -> f32 {
        self.0
    }
}

impl Into<i32> for DecimalF32 {
    fn into(self) -> i32 {
        self.0 as i32
    }
}

impl Into<u32> for DecimalF32 {
    fn into(self) -> u32 {
        self.0 as u32
    }
}

impl PartialEq for DecimalF32 {
    fn eq(
        &self,
        other: &Self,
    ) -> bool {
        self.0 == other.0
    }
}

impl Eq for DecimalF32 {}

impl std::hash::Hash for DecimalF32 {
    fn hash<H: Hasher>(
        &self,
        state: &mut H,
    ) {
        let bits: u32 = self.0.to_bits();
        bits.hash(state);
    }
}

// This is an f64 that supports Hash and Eq. Generally this is dangerous, but here we're
// not doing any sort of fp-arithmetic and not expecting NaN. We should be deterministically
// parsing a string and creating a float from it.
#[derive(Debug, Copy, Clone, Default)]
pub struct DecimalF64(pub f64);

impl Into<f64> for DecimalF64 {
    fn into(self) -> f64 {
        self.0
    }
}

impl Into<f32> for DecimalF64 {
    fn into(self) -> f32 {
        self.0 as f32
    }
}

impl Into<i32> for DecimalF64 {
    fn into(self) -> i32 {
        self.0 as i32
    }
}

impl Into<u32> for DecimalF64 {
    fn into(self) -> u32 {
        self.0 as u32
    }
}

impl PartialEq for DecimalF64 {
    fn eq(
        &self,
        other: &Self,
    ) -> bool {
        self.0 == other.0
    }
}

impl Eq for DecimalF64 {}

impl std::hash::Hash for DecimalF64 {
    fn hash<H: Hasher>(
        &self,
        state: &mut H,
    ) {
        let bits: u64 = self.0.to_bits();
        bits.hash(state);
    }
}