Skip to content

Commit e7352f7

Browse files
authored
Merge pull request #94 from distil/float-bit-comparison
bit comparison of f32, f64
2 parents 9fca4ea + 8f2e972 commit e7352f7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

diffus/src/diffable_impls/primitives.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ macro_rules! primitive_impl {
77
type Diff = (&'a $typ, &'a $typ);
88

99
fn diff(&'a self, other: &'a Self) -> edit::Edit<Self> {
10-
if self == other {
10+
use crate::Same;
11+
if self.same(other) {
1112
edit::Edit::Copy(self)
1213
} else {
1314
edit::Edit::Change((self, other))
@@ -18,7 +19,7 @@ macro_rules! primitive_impl {
1819
}
1920
}
2021

21-
primitive_impl! { i64, i32, i16, i8, u64, u32, u16, u8, char, bool, isize, usize, () }
22+
primitive_impl! { i64, i32, i16, i8, u64, u32, u16, u8, char, bool, isize, usize, f32, f64, () }
2223

2324
#[cfg(feature = "uuid-impl")]
2425
primitive_impl! { uuid::Uuid }

diffus/src/same.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@ macro_rules! same_for_eq {
2222
}
2323
}
2424

25-
same_for_eq! { u8, u16, u32, u64, i8, i16, i32, i64, char, str, String }
25+
same_for_eq! { i64, i32, i16, i8, u64, u32, u16, u8, char, str, bool, isize, usize, () }
26+
27+
macro_rules! same_for_float {
28+
($($typ:ty),*) => {
29+
$(
30+
impl Same for $typ {
31+
fn same(&self, other: &Self) -> bool {
32+
self.to_ne_bytes() == other.to_ne_bytes()
33+
}
34+
}
35+
)*
36+
}
37+
}
38+
39+
same_for_float! { f32, f64 }
2640

2741
#[cfg(feature = "snake_case-impl")]
2842
same_for_eq! { snake_case::SnakeCase }

0 commit comments

Comments
 (0)