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
use std::ops::Sub;
use num_traits::identities::One;
use typenum::{Cmp, Greater, Less, U0, U8, U16, U32, Unsigned};
use fpa::*;
use NearlyEq;
macro_rules! impl_fpa {
($bits:ident, $limit:ident) => {
#[cfg_attr(feature = "docs", stable(feature = "fpa", since = "0.2.4"))]
impl<FRAC> NearlyEq<Q<$bits, FRAC>, Q<$bits, FRAC>> for Q<$bits, FRAC>
where
FRAC: Cmp<U0, Output = Greater> + Cmp<$limit, Output = Less> + Unsigned,
Self: PartialOrd + Clone + Sub<Self, Output=Self>,
{
fn eps() -> Self {
Self::from_bits(One::one())
}
fn eq(&self, other: &Self, eps: &Self) -> bool {
println!();
println!("self: {:?} ({})", *self, *self);
println!("other: {:?} ({})", other, other);
let diff = if *self > *other {
self.clone() - other.clone()
} else {
other.clone() - self.clone()
};
println!("diff: {:?} ({})", diff, diff);
println!("eps: {:?} ({})", *eps, *eps);
println!();
if *self == *other {
true
} else {
diff <= *eps
}
}
}
}
}
impl_fpa!(i8, U8);
impl_fpa!(i16, U16);
impl_fpa!(i32, U32);