Skip to content

Commit 153cf68

Browse files
committed
ppc64le - Fix deviation in floating point values caused by FMA
This was exposed while testing CockroachDB. Following tests from pkg/sql/opt/exec/execbuilder fail due to floating point precision differences caused by FMA: - TestExecBuild/local/geospatial - TestExecBuild/local-vec-off/geospatial - TestExecBuild/local-spec-planning/geospatial - TestExecBuild/fakedist/geospatial - TestExecBuild/fakedist-vec-off/geospatial - TestExecBuild/fakedist-metadata/geospatial - TestExecBuild/fakedist-disk/geospatial - TestExecBuild/fakedist-spec-planning/geospatial With explicit casts in this patch, these failures are resolved. References: https://go.dev/ref/spec#Floating_point_operators golang/go#53297 golang/go#48145 disintegration/gift#20 (comment)
1 parent 740aa86 commit 153cf68

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

s2/latlng.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ func (ll LatLng) Distance(ll2 LatLng) s1.Angle {
6464
lng1, lng2 := ll.Lng.Radians(), ll2.Lng.Radians()
6565
dlat := math.Sin(0.5 * (lat2 - lat1))
6666
dlng := math.Sin(0.5 * (lng2 - lng1))
67-
x := dlat*dlat + dlng*dlng*math.Cos(lat1)*math.Cos(lat2)
67+
x := float64(dlat*dlat) + float64(dlng*dlng*math.Cos(lat1)*math.Cos(lat2))
6868
return s1.Angle(2*math.Atan2(math.Sqrt(x), math.Sqrt(math.Max(0, 1-x)))) * s1.Radian
6969
}
7070

7171
// NOTE(mikeperrow): The C++ implementation publicly exposes latitude/longitude
7272
// functions. Let's see if that's really necessary before exposing the same functionality.
7373

7474
func latitude(p Point) s1.Angle {
75-
return s1.Angle(math.Atan2(p.Z, math.Sqrt(p.X*p.X+p.Y*p.Y))) * s1.Radian
75+
return s1.Angle(math.Atan2(p.Z, math.Sqrt(float64(p.X*p.X)+float64(p.Y*p.Y)))) * s1.Radian
7676
}
7777

7878
func longitude(p Point) s1.Angle {

0 commit comments

Comments
 (0)