diff --git a/pkg/geo/geomfn/BUILD.bazel b/pkg/geo/geomfn/BUILD.bazel index 5aeb0800f3f6..34e3dddf7741 100644 --- a/pkg/geo/geomfn/BUILD.bazel +++ b/pkg/geo/geomfn/BUILD.bazel @@ -111,6 +111,7 @@ go_test( "//pkg/geo/geopb", "//pkg/geo/geos", "//pkg/geo/geotest", + "//pkg/testutils/floatcmp", "@com_github_cockroachdb_errors//:errors", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", diff --git a/pkg/geo/geomfn/angle_test.go b/pkg/geo/geomfn/angle_test.go index 18ac4fc222a7..32c543a70c88 100644 --- a/pkg/geo/geomfn/angle_test.go +++ b/pkg/geo/geomfn/angle_test.go @@ -8,13 +8,32 @@ package geomfn import ( "fmt" "math" + "runtime" + "strconv" "testing" "github.com/cockroachdb/cockroach/pkg/geo" "github.com/cockroachdb/cockroach/pkg/geo/geopb" + "github.com/cockroachdb/cockroach/pkg/testutils/floatcmp" "github.com/stretchr/testify/require" ) +func assertFloatsMatch(t *testing.T, expected, actual float64) { + if runtime.GOARCH != "s390x" { + require.Equal(t, expected, actual) + return + } + // s390x system has architecture support for 'atan' function (which is used + // in 'angleFromCoords') and produces slightly different result than math + // operations we do to get the expected number. To go around this, we use + // the custom float comparison that checks 15 significant decimal digits. + exp := strconv.FormatFloat(expected, 'f', -1, 64) + act := strconv.FormatFloat(actual, 'f', -1, 64) + matched, err := floatcmp.FloatsMatch(exp, act) + require.NoError(t, err) + require.True(t, matched) +} + func TestAngle(t *testing.T) { pf := func(f float64) *float64 { return &f @@ -58,7 +77,7 @@ func TestAngle(t *testing.T) { angle, err := Angle(g1, g2, g3, g4) require.NoError(t, err) if tc.expected != nil && angle != nil { - require.Equal(t, *tc.expected, *angle) + assertFloatsMatch(t, *tc.expected, *angle) } else { require.Equal(t, tc.expected, angle) } @@ -134,7 +153,7 @@ func TestAngleLineString(t *testing.T) { angle, err := AngleLineString(g1, g2) require.NoError(t, err) if tc.expected != nil && angle != nil { - require.Equal(t, *tc.expected, *angle) + assertFloatsMatch(t, *tc.expected, *angle) } else { require.Equal(t, tc.expected, angle) }