@@ -12,6 +12,11 @@ theorem Float.toBits_inj {x y : Float} : x.toBits = y.toBits ↔ x = y := by
1212 · rintro rfl
1313 rfl
1414
15+ -- not sure whether we want this
16+ -- `0 ≠ -0` but `nan = nan`
17+ instance : DecidableEq Float := fun _ _ =>
18+ decidable_of_decidable_of_iff Float.toBits_inj
19+
1520example : (2047 <<< 52 ||| 2251799813685248 ) >>> 52 &&& 2047 = 2047 := by
1621 simp
1722
@@ -89,7 +94,29 @@ theorem Float.mantissa_neg (x : Float) : (-x).mantissa = x.mantissa := by
8994 simpa [isNaNBits, ← UInt64.toNat_inj, Nat.shiftRight_xor_distrib,
9095 Nat.and_xor_distrib_right] using h
9196
92- -- not sure whether we want this
93- -- `0 ≠ -0` but `nan = nan`
94- instance : DecidableEq Float := fun _ _ =>
95- decidable_of_decidable_of_iff Float.toBits_inj
97+ theorem Float.beq_def (x y : Float) : (x == y) = x.beq y := rfl
98+
99+ @[simp]
100+ theorem Float.not_nan_beq (x : Float) : (nan == x) = false := by
101+ rw [beq_def, beq]
102+ simp only [isNaN_nan, true_or, ↓reduceIte]
103+
104+ @[simp]
105+ theorem Float.not_beq_nan (x : Float) : (x == nan) = false := by
106+ rw [beq_def, beq]
107+ simp only [isNaN_nan, or_true, ↓reduceIte]
108+
109+ @[simp]
110+ theorem Float.beq_self_eq (x : Float) : (x == x) = decide (x ≠ nan) := by
111+ rw [beq_def, beq]
112+ simp [Float.isNaN_iff_eq_nan]
113+
114+ @[simp]
115+ theorem Float.beq_self_iff (x : Float) : x == x ↔ x ≠ nan := by
116+ simp
117+
118+ -- `a != b` is simplified to `!(a == b)` to ensure simp confluency
119+ @[simp]
120+ theorem Float.bne_eq_not_beq (x y : Float) : (x != y) = !(x == y) := rfl
121+
122+ example : Float.nan != Float.nan := by simp
0 commit comments