diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-17 22:03:27 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-17 22:03:27 +0100 |
commit | b80853de90b10171155b8f3fde47d64ec7bfa0dd (patch) | |
tree | 435d3dbf7a495a0c6ce64c9769e037179aa0d27b /tpl/math | |
parent | 423594e03a906ef4150f433666ff588b022c3c92 (diff) |
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
Diffstat (limited to 'tpl/math')
-rw-r--r-- | tpl/math/init.go | 2 | ||||
-rw-r--r-- | tpl/math/math.go | 28 | ||||
-rw-r--r-- | tpl/math/math_test.go | 58 |
3 files changed, 44 insertions, 44 deletions
diff --git a/tpl/math/init.go b/tpl/math/init.go index 32315d362..b4b002a78 100644 --- a/tpl/math/init.go +++ b/tpl/math/init.go @@ -26,7 +26,7 @@ func init() { ns := &internal.TemplateFuncsNamespace{ Name: name, - Context: func(args ...interface{}) (interface{}, error) { return ctx, nil }, + Context: func(args ...any) (any, error) { return ctx, nil }, } ns.AddMethodMapping(ctx.Add, diff --git a/tpl/math/math.go b/tpl/math/math.go index cd4a47eca..fce44dc4b 100644 --- a/tpl/math/math.go +++ b/tpl/math/math.go @@ -33,12 +33,12 @@ func New() *Namespace { type Namespace struct{} // Add adds two numbers. -func (ns *Namespace) Add(a, b interface{}) (interface{}, error) { +func (ns *Namespace) Add(a, b any) (any, error) { return _math.DoArithmetic(a, b, '+') } // Ceil returns the least integer value greater than or equal to x. -func (ns *Namespace) Ceil(x interface{}) (float64, error) { +func (ns *Namespace) Ceil(x any) (float64, error) { xf, err := cast.ToFloat64E(x) if err != nil { return 0, errors.New("Ceil operator can't be used with non-float value") @@ -48,12 +48,12 @@ func (ns *Namespace) Ceil(x interface{}) (float64, error) { } // Div divides two numbers. -func (ns *Namespace) Div(a, b interface{}) (interface{}, error) { +func (ns *Namespace) Div(a, b any) (any, error) { return _math.DoArithmetic(a, b, '/') } // Floor returns the greatest integer value less than or equal to x. -func (ns *Namespace) Floor(x interface{}) (float64, error) { +func (ns *Namespace) Floor(x any) (float64, error) { xf, err := cast.ToFloat64E(x) if err != nil { return 0, errors.New("Floor operator can't be used with non-float value") @@ -63,7 +63,7 @@ func (ns *Namespace) Floor(x interface{}) (float64, error) { } // Log returns the natural logarithm of a number. -func (ns *Namespace) Log(a interface{}) (float64, error) { +func (ns *Namespace) Log(a any) (float64, error) { af, err := cast.ToFloat64E(a) if err != nil { return 0, errors.New("Log operator can't be used with non integer or float value") @@ -73,7 +73,7 @@ func (ns *Namespace) Log(a interface{}) (float64, error) { } // Max returns the greater of two numbers. -func (ns *Namespace) Max(a, b interface{}) (float64, error) { +func (ns *Namespace) Max(a, b any) (float64, error) { af, erra := cast.ToFloat64E(a) bf, errb := cast.ToFloat64E(b) @@ -85,7 +85,7 @@ func (ns *Namespace) Max(a, b interface{}) (float64, error) { } // Min returns the smaller of two numbers. -func (ns *Namespace) Min(a, b interface{}) (float64, error) { +func (ns *Namespace) Min(a, b any) (float64, error) { af, erra := cast.ToFloat64E(a) bf, errb := cast.ToFloat64E(b) @@ -97,7 +97,7 @@ func (ns *Namespace) Min(a, b interface{}) (float64, error) { } // Mod returns a % b. -func (ns *Namespace) Mod(a, b interface{}) (int64, error) { +func (ns *Namespace) Mod(a, b any) (int64, error) { ai, erra := cast.ToInt64E(a) bi, errb := cast.ToInt64E(b) @@ -113,7 +113,7 @@ func (ns *Namespace) Mod(a, b interface{}) (int64, error) { } // ModBool returns the boolean of a % b. If a % b == 0, return true. -func (ns *Namespace) ModBool(a, b interface{}) (bool, error) { +func (ns *Namespace) ModBool(a, b any) (bool, error) { res, err := ns.Mod(a, b) if err != nil { return false, err @@ -123,12 +123,12 @@ func (ns *Namespace) ModBool(a, b interface{}) (bool, error) { } // Mul multiplies two numbers. -func (ns *Namespace) Mul(a, b interface{}) (interface{}, error) { +func (ns *Namespace) Mul(a, b any) (any, error) { return _math.DoArithmetic(a, b, '*') } // Pow returns a raised to the power of b. -func (ns *Namespace) Pow(a, b interface{}) (float64, error) { +func (ns *Namespace) Pow(a, b any) (float64, error) { af, erra := cast.ToFloat64E(a) bf, errb := cast.ToFloat64E(b) @@ -140,7 +140,7 @@ func (ns *Namespace) Pow(a, b interface{}) (float64, error) { } // Round returns the nearest integer, rounding half away from zero. -func (ns *Namespace) Round(x interface{}) (float64, error) { +func (ns *Namespace) Round(x any) (float64, error) { xf, err := cast.ToFloat64E(x) if err != nil { return 0, errors.New("Round operator can't be used with non-float value") @@ -150,7 +150,7 @@ func (ns *Namespace) Round(x interface{}) (float64, error) { } // Sqrt returns the square root of a number. -func (ns *Namespace) Sqrt(a interface{}) (float64, error) { +func (ns *Namespace) Sqrt(a any) (float64, error) { af, err := cast.ToFloat64E(a) if err != nil { return 0, errors.New("Sqrt operator can't be used with non integer or float value") @@ -160,7 +160,7 @@ func (ns *Namespace) Sqrt(a interface{}) (float64, error) { } // Sub subtracts two numbers. -func (ns *Namespace) Sub(a, b interface{}) (interface{}, error) { +func (ns *Namespace) Sub(a, b any) (any, error) { return _math.DoArithmetic(a, b, '-') } diff --git a/tpl/math/math_test.go b/tpl/math/math_test.go index 45f28e093..cdec43d5f 100644 --- a/tpl/math/math_test.go +++ b/tpl/math/math_test.go @@ -27,10 +27,10 @@ func TestBasicNSArithmetic(t *testing.T) { ns := New() for _, test := range []struct { - fn func(a, b interface{}) (interface{}, error) - a interface{} - b interface{} - expect interface{} + fn func(a, b any) (any, error) + a any + b any + expect any }{ {ns.Add, 4, 2, int64(6)}, {ns.Add, 1.0, "foo", false}, @@ -60,8 +60,8 @@ func TestCeil(t *testing.T) { ns := New() for _, test := range []struct { - x interface{} - expect interface{} + x any + expect any }{ {0.1, 1.0}, {0.5, 1.0}, @@ -93,8 +93,8 @@ func TestFloor(t *testing.T) { ns := New() for _, test := range []struct { - x interface{} - expect interface{} + x any + expect any }{ {0.1, 0.0}, {0.5, 0.0}, @@ -126,8 +126,8 @@ func TestLog(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - expect interface{} + a any + expect any }{ {1, float64(0)}, {3, float64(1.0986)}, @@ -167,8 +167,8 @@ func TestSqrt(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - expect interface{} + a any + expect any }{ {81, float64(9)}, {0.25, float64(0.5)}, @@ -206,9 +206,9 @@ func TestMod(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - b interface{} - expect interface{} + a any + b any + expect any }{ {3, 2, int64(1)}, {3, 1, int64(0)}, @@ -246,9 +246,9 @@ func TestModBool(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - b interface{} - expect interface{} + a any + b any + expect any }{ {3, 3, true}, {3, 2, false}, @@ -292,8 +292,8 @@ func TestRound(t *testing.T) { ns := New() for _, test := range []struct { - x interface{} - expect interface{} + x any + expect any }{ {0.1, 0.0}, {0.5, 1.0}, @@ -325,9 +325,9 @@ func TestPow(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - b interface{} - expect interface{} + a any + b any + expect any }{ {0, 0, float64(1)}, {2, 0, float64(1)}, @@ -365,9 +365,9 @@ func TestMax(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - b interface{} - expect interface{} + a any + b any + expect any }{ {-1, -1, float64(-1)}, {-1, 0, float64(0)}, @@ -404,9 +404,9 @@ func TestMin(t *testing.T) { ns := New() for _, test := range []struct { - a interface{} - b interface{} - expect interface{} + a any + b any + expect any }{ {-1, -1, float64(-1)}, {-1, 0, float64(-1)}, |