Skip to content

Commit 105d3bc

Browse files
toddy15bep
authored andcommitted
tpl: Workaround s390x precision of Atan and Tan
On s390x, math.Atan(1) and math.Tan(1) give values that slightly differ from other architectures, causing TestTemplateFuncsExamples to fail. The golang math package states in the overview: "This package does not guarantee bit-identical results across architectures."
1 parent 3e46ba5 commit 105d3bc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎tpl/math/init.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package math
1515

1616
import (
1717
"context"
18+
"runtime"
1819

1920
"github.com/gohugoio/hugo/deps"
2021
"github.com/gohugoio/hugo/tpl/internal"
@@ -23,6 +24,13 @@ import (
2324
const name = "math"
2425

2526
func init() {
27+
mathAtan1 := "0.7853981633974483"
28+
mathTan1 := "1.557407724654902"
29+
if runtime.GOARCH == "s390x" {
30+
mathAtan1 = "0.7853981633974484"
31+
mathTan1 = "1.5574077246549018"
32+
}
33+
2634
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
2735
ctx := New(d)
2836

@@ -62,7 +70,7 @@ func init() {
6270
ns.AddMethodMapping(ctx.Atan,
6371
nil,
6472
[][2]string{
65-
{"{{ math.Atan 1 }}", "0.7853981633974483"},
73+
{"{{ math.Atan 1 }}", mathAtan1},
6674
},
6775
)
6876

@@ -202,7 +210,7 @@ func init() {
202210
ns.AddMethodMapping(ctx.Tan,
203211
nil,
204212
[][2]string{
205-
{"{{ math.Tan 1 }}", "1.557407724654902"},
213+
{"{{ math.Tan 1 }}", mathTan1},
206214
},
207215
)
208216

0 commit comments

Comments
 (0)