Skip to content

Commit 15e768d

Browse files
committed
Add unit tests about float32 vs float64 comparaison
1 parent c3a5161 commit 15e768d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

assert/assertions_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ func TestObjectsAreEqualValues(t *testing.T) {
170170
{float32(10.123456), float64(10.12345600), true},
171171
{float32(10.123456), float64(10.12345678), false},
172172
{float32(1.0 / 3.0), float64(1.0 / 3.0), false},
173+
174+
// Something near overflow should work
175+
{float32(math.MaxFloat32), float64(math.MaxFloat32), true},
176+
177+
// NaN should remain unequal, even across float32/float64.
178+
{float32(math.NaN()), float64(math.NaN()), false},
179+
180+
// Infinity should compare like ordinary equality.
181+
{float32(math.Inf(1)), float64(math.Inf(1)), true},
182+
{float32(math.Inf(-1)), float64(math.Inf(-1)), true},
183+
{float64(math.Inf(1)), float32(math.Inf(-1)), false},
184+
185+
// zero should not lead to division by zero error
186+
{float32(0), float64(0), true},
187+
188+
// Signed zero should still compare equal.
189+
{float32(math.Copysign(0, -1)), float64(0), true},
173190
}
174191

175192
for _, c := range cases {

0 commit comments

Comments
 (0)