Browse Source

math: fix math.Max and math.Min

The math package failed the package tests on arm64 and wasm:

    GOARCH=arm64 tinygo test math

Apparently the builtins llvm.maximum.f64 and llvm.minimum.f64 have
slightly different behavior on arm64 and wasm compared to what Go
expects.
pull/2039/head
Ayke van Laethem 3 years ago
committed by Ron Evans
parent
commit
6c1301688b
  1. 20
      src/runtime/math.go

20
src/runtime/math.go

@ -168,29 +168,13 @@ func math_Log2(x float64) float64 { return math_log2(x) }
func math_log2(x float64) float64
//go:linkname math_Max math.Max
func math_Max(x, y float64) float64 {
if GOARCH == "arm64" || GOARCH == "wasm" {
return llvm_maximum(x, y)
}
return math_max(x, y)
}
//export llvm.maximum.f64
func llvm_maximum(x, y float64) float64
func math_Max(x, y float64) float64 { return math_max(x, y) }
//go:linkname math_max math.max
func math_max(x, y float64) float64
//go:linkname math_Min math.Min
func math_Min(x, y float64) float64 {
if GOARCH == "arm64" || GOARCH == "wasm" {
return llvm_minimum(x, y)
}
return math_min(x, y)
}
//export llvm.minimum.f64
func llvm_minimum(x, y float64) float64
func math_Min(x, y float64) float64 { return math_min(x, y) }
//go:linkname math_min math.min
func math_min(x, y float64) float64

Loading…
Cancel
Save