forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I added special NaN handling for float comparisons. In SQL, NaNs are treated as less than any other float value. Thankfully I'm not seeing a performance hit when I run our sort benchmarks with float64 values. Fixes cockroachdb#38751 Release note: None
- Loading branch information
1 parent
d7232ed
commit 540d2f8
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package exec | ||
|
||
import "math" | ||
|
||
// compareFloats compares two float values. This function is necessary for NaN | ||
// handling. In SQL, NaN is treated as less than all other float values. In Go, | ||
// any comparison with NaN returns false. | ||
func compareFloats(a, b float64) int { | ||
if a < b { | ||
return -1 | ||
} | ||
if a == b { | ||
return 0 | ||
} | ||
if a > b { | ||
return 1 | ||
} | ||
if math.IsNaN(a) { | ||
if math.IsNaN(b) { | ||
return 0 | ||
} | ||
return -1 | ||
} | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters