Skip to content

Commit 325a0db

Browse files
jmooringbep
authored andcommitted
tpl/math: Add MaxInt64 function
Closes #13693
1 parent d70f828 commit 325a0db

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

‎tpl/math/init.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ func init() {
115115
},
116116
)
117117

118+
ns.AddMethodMapping(ctx.MaxInt64,
119+
nil,
120+
[][2]string{
121+
{"{{ math.MaxInt64 }}", "9223372036854775807"},
122+
},
123+
)
124+
118125
ns.AddMethodMapping(ctx.Min,
119126
nil,
120127
[][2]string{

‎tpl/math/math.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func (ns *Namespace) Max(inputs ...any) (maximum float64, err error) {
147147
return ns.applyOpToScalarsOrSlices("Max", math.Max, inputs...)
148148
}
149149

150+
// MaxInt64 returns the maximum value for a signed 64-bit integer.
151+
func (ns *Namespace) MaxInt64() int64 {
152+
return math.MaxInt64
153+
}
154+
150155
// Min returns the smaller of all numbers in inputs. Any slices in inputs are flattened.
151156
func (ns *Namespace) Min(inputs ...any) (minimum float64, err error) {
152157
return ns.applyOpToScalarsOrSlices("Min", math.Min, inputs...)

‎tpl/math/math_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,14 @@ func TestToRadians(t *testing.T) {
879879
c.Assert(result, qt.Equals, test.expect)
880880
}
881881
}
882+
883+
func TestMaxInt64(t *testing.T) {
884+
t.Parallel()
885+
ns := New(nil)
886+
887+
var want int64 = 9223372036854775807
888+
got := ns.MaxInt64()
889+
if want != got {
890+
t.Errorf("want %d, got %d", want, got)
891+
}
892+
}

0 commit comments

Comments
 (0)