-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 #38751 Release note: None
- Loading branch information
1 parent
d7232ed
commit 9bec27f
Showing
4 changed files
with
53 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,34 @@ | ||
// 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 1 | ||
} | ||
// Compare bits so that NaN == NaN. | ||
if math.Float64bits(a) == math.Float64bits(b) { | ||
return 0 | ||
} | ||
// Either a or b is NaN. | ||
if math.IsNaN(a) { | ||
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