aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2023-02-10 14:39:20 +0000
committerThan McIntosh <thanm@google.com>2023-02-10 18:08:07 +0000
commitac8a97ac9e5de94d1c0e830299ce6487cbbfd3f6 (patch)
treeb69a9fe7da1662df65c4319b238186c72c480d81
parentaa5b22552ac353c79ad1e8b6202ab4fa131338ef (diff)
downloadgo-ac8a97ac9e5de94d1c0e830299ce6487cbbfd3f6.tar.xz
Revert "math: add Compare and Compare32"
This reverts CL 459435. Reason for revert: Tests failing on MIPS. Change-Id: I9017bf718ba938df6d6766041555034d55d90b8a Reviewed-on: https://go-review.googlesource.com/c/go/+/467255 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Akhil Indurti <aindurti@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
-rw-r--r--api/next/56491.txt2
-rw-r--r--src/math/all_test.go59
-rw-r--r--src/math/compare.go53
3 files changed, 0 insertions, 114 deletions
diff --git a/api/next/56491.txt b/api/next/56491.txt
deleted file mode 100644
index 333f92e215..0000000000
--- a/api/next/56491.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-pkg math, func Compare(float64, float64) int #56491
-pkg math, func Compare32(float32, float32) int #56491
diff --git a/src/math/all_test.go b/src/math/all_test.go
index a37bf8a2be..886267bc17 100644
--- a/src/math/all_test.go
+++ b/src/math/all_test.go
@@ -2094,33 +2094,6 @@ var sqrt32 = []float32{
-5.0106036182710749e+00,
}
-type compareTest[F float32 | float64] struct {
- x, y F
- want int
-}
-
-func compareCases[F float32 | float64]() []compareTest[F] {
- zero, nan, inf := F(0.0), F(NaN()), F(Inf(0))
- return []compareTest[F]{
- {-nan, -inf, -1},
- {-inf, -nan, 1},
- {-inf, -Pi, -1},
- {-Pi, -inf, 1},
- {-Pi, -zero, -1},
- {-zero, -Pi, 1},
- {-zero, 0, -1},
- {0, -zero, 1},
- {0, Pi, -1},
- {Pi, 0, 1},
- {Pi, inf, -1},
- {inf, Pi, 1},
- {inf, nan, -1},
- {nan, inf, 1},
- {Pi, Pi, 0},
- {-nan, -nan, 0},
- }
-}
-
func tolerance(a, b, e float64) bool {
// Multiplying by e here can underflow denormal values to zero.
// Check a==b so that at least if a and b are small and identical
@@ -2288,22 +2261,6 @@ func TestCeil(t *testing.T) {
}
}
-func TestCompare(t *testing.T) {
- // -NaN < -∞ < -3.14 < -0 < 0 < 3.14 < ∞ < NaN
- for _, c := range compareCases[float64]() {
- cmp := Compare(c.x, c.y)
- if cmp != c.want {
- t.Errorf("Compare(%v, %v) = %d, want %v", c.x, c.y, cmp, c.want)
- }
- }
- for _, c := range compareCases[float32]() {
- cmp := Compare32(c.x, c.y)
- if cmp != c.want {
- t.Errorf("Compare32(%v, %v) = %d, want %v", c.x, c.y, cmp, c.want)
- }
- }
-}
-
func TestCopysign(t *testing.T) {
for i := 0; i < len(vf); i++ {
if f := Copysign(vf[i], -1); copysign[i] != f {
@@ -3363,22 +3320,6 @@ func BenchmarkCeil(b *testing.B) {
GlobalF = x
}
-func BenchmarkCompare(b *testing.B) {
- x := 0
- for i := 0; i < b.N; i++ {
- x = Compare(1.5, 2.5)
- }
- GlobalI = x
-}
-
-func BenchmarkCompare32(b *testing.B) {
- x := 0
- for i := 0; i < b.N; i++ {
- x = Compare32(1.5, 2.5)
- }
- GlobalI = x
-}
-
var copysignNeg = -1.0
func BenchmarkCopysign(b *testing.B) {
diff --git a/src/math/compare.go b/src/math/compare.go
deleted file mode 100644
index 3798110072..0000000000
--- a/src/math/compare.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2023 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package math
-
-func sign[I int32 | int64](a, b I) int {
- if a < b {
- return -1
- }
- if a > b {
- return 1
- }
- return 0
-}
-
-// Compare compares a and b such that
-// -NaN is ordered before any other value,
-// +NaN is ordered after any other value,
-// and -0 is ordered before +0.
-// In other words, it defines a total order over floats
-// (according to the total-ordering predicate in IEEE-754, section 5.10).
-// It returns 0 if a == b, -1 if a < b, and +1 if a > b.
-func Compare(a, b float64) int {
- // Perform a bitwise comparison (a < b) by casting the float64s into an int64s.
- x := int64(Float64bits(a))
- y := int64(Float64bits(b))
-
- // If a and b are both negative, flip the comparison so that we check a > b.
- if x < 0 && y < 0 {
- return sign(y, x)
- }
- return sign(x, y)
-}
-
-// Compare32 compares a and b such that
-// -NaN is ordered before any other value,
-// +NaN is ordered after any other value,
-// and -0 is ordered before +0.
-// In other words, it defines a total order over floats
-// (according to the total-ordering predicate in IEEE-754, section 5.10).
-// It returns 0 if a == b, -1 if a < b, and +1 if a > b.
-func Compare32(a, b float32) int {
- // Perform a bitwise comparison (a < b) by casting the float32s into an int32s.
- x := int32(Float32bits(a))
- y := int32(Float32bits(b))
-
- // If a and b are both negative, flip the comparison so that we check a > b.
- if x < 0 && y < 0 {
- return sign(y, x)
- }
- return sign(x, y)
-}