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
use std::cmp::Ordering;
#[derive(Clone, Debug)]
pub struct Double(pub f64);
impl Double {
fn canonicalize(&self) -> i64 {
(self.0 * 1024.0 * 1024.0).round() as i64
}
}
impl PartialEq for Double {
fn eq(&self, other: &Double) -> bool {
self.canonicalize() == other.canonicalize()
}
}
impl Eq for Double {}
impl PartialOrd for Double {
fn partial_cmp(&self, other: &Double) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Double {
fn cmp(&self, other: &Double) -> Ordering {
self.canonicalize().cmp(&other.canonicalize())
}
}
impl<P> ::fbthrift::Serialize<P> for Double
where
P: ::fbthrift::ProtocolWriter,
{
#[inline]
fn write(&self, p: &mut P) {
p.write_double(self.0)
}
}
impl<P> ::fbthrift::Deserialize<P> for Double
where
P: ::fbthrift::ProtocolReader,
{
#[inline]
fn read(p: &mut P) -> ::anyhow::Result<Self> {
::std::result::Result::Ok(Self(p.read_double()?))
}
}