Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compare float with NaN #32

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

// 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
Loading