checkito/
nudge.rs

1pub trait Nudge {
2    fn nudge(self, force: Self) -> Self;
3}
4
5macro_rules! floating {
6    ($t:ty) => {
7        impl Nudge for $t {
8            #[inline]
9            fn nudge(self, force: Self) -> Self {
10                if self == 0.0 {
11                    force / Self::MAX
12                } else if self == -0.0 {
13                    force / Self::MIN
14                } else {
15                    self * (1.0 + Self::EPSILON * force)
16                }
17            }
18        }
19    };
20    ($($t:ty),*) => { $(floating!($t);)* }
21}
22
23floating!(f32, f64);