From 325a0dba63252599826c3ecc955c7919a4a3ba39 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Tue, 6 May 2025 11:57:03 -0700 Subject: [PATCH] tpl/math: Add MaxInt64 function Closes #13693 --- tpl/math/init.go | 7 +++++++ tpl/math/math.go | 5 +++++ tpl/math/math_test.go | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/tpl/math/init.go b/tpl/math/init.go index bfaf4526a..bb3c02bd6 100644 --- a/tpl/math/init.go +++ b/tpl/math/init.go @@ -115,6 +115,13 @@ func init() { }, ) + ns.AddMethodMapping(ctx.MaxInt64, + nil, + [][2]string{ + {"{{ math.MaxInt64 }}", "9223372036854775807"}, + }, + ) + ns.AddMethodMapping(ctx.Min, nil, [][2]string{ diff --git a/tpl/math/math.go b/tpl/math/math.go index a0512c045..01e75e9c8 100644 --- a/tpl/math/math.go +++ b/tpl/math/math.go @@ -147,6 +147,11 @@ func (ns *Namespace) Max(inputs ...any) (maximum float64, err error) { return ns.applyOpToScalarsOrSlices("Max", math.Max, inputs...) } +// MaxInt64 returns the maximum value for a signed 64-bit integer. +func (ns *Namespace) MaxInt64() int64 { + return math.MaxInt64 +} + // Min returns the smaller of all numbers in inputs. Any slices in inputs are flattened. func (ns *Namespace) Min(inputs ...any) (minimum float64, err error) { return ns.applyOpToScalarsOrSlices("Min", math.Min, inputs...) diff --git a/tpl/math/math_test.go b/tpl/math/math_test.go index d45a2aace..cc4fe31eb 100644 --- a/tpl/math/math_test.go +++ b/tpl/math/math_test.go @@ -879,3 +879,14 @@ func TestToRadians(t *testing.T) { c.Assert(result, qt.Equals, test.expect) } } + +func TestMaxInt64(t *testing.T) { + t.Parallel() + ns := New(nil) + + var want int64 = 9223372036854775807 + got := ns.MaxInt64() + if want != got { + t.Errorf("want %d, got %d", want, got) + } +}