Skip to content

Commit

Permalink
Merge pull request #32 from zxh126/compare_with_NaN
Browse files Browse the repository at this point in the history
compare float with NaN
  • Loading branch information
liyue201 authored Jan 2, 2025
2 parents c22c7dc + 255e870 commit 5aea2d6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions utils/comparator/comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,31 @@ func Uint64Comparator(a, b uint64) int {

// Float32Comparator compare a with b
//
// -1 , if a < b
// 0 , if a == b
// 1 , if a > b
// -1 , if a < b or a is NaN and b is not NaN
// 0 , if a == b or a is NaN and b is NaN
// 1 , if a > b or a is not NaN and b is NaN
func Float32Comparator(a, b float32) int {
if a == b {
aIsNaN, bIsNaN := math.IsNaN(float64(a)), math.IsNaN(float64(b))

Check failure on line 203 in utils/comparator/comparator.go

View workflow job for this annotation

GitHub Actions / Build

undefined: math
if a == b || (aIsNaN && bIsNaN) {
return 0
}
if a < b {
if a < b || aIsNaN {
return -1
}
return 1
}

// Float64Comparator compare a with b
//
// -1 , if a < b
// 0 , if a == b
// 1 , if a > b
// -1 , if a < b or a is NaN and b is not NaN
// 0 , if a == b or a is NaN and b is NaN
// 1 , if a > b or a is not NaN and b is NaN
func Float64Comparator(a, b float64) int {
if a == b {
aIsNaN, bIsNaN := math.IsNaN(a), math.IsNaN(b)

Check failure on line 219 in utils/comparator/comparator.go

View workflow job for this annotation

GitHub Actions / Build

undefined: math
if a == b || (aIsNaN && bIsNaN) {
return 0
}
if a < b {
if a < b || aIsNaN {
return -1
}
return 1
Expand Down

0 comments on commit 5aea2d6

Please sign in to comment.