summaryrefslogtreecommitdiffstats
path: root/tpl/math/math.go
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2020-05-13 13:35:07 -0400
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-05-14 10:00:31 +0200
commit991934497e88dcd4134a369a213bb5072c51c139 (patch)
treed8a6aa405dc93f821dc1b389f70827e14fea6bce /tpl/math/math.go
parent558c09305e2be16953238c6c0e828f62b950e4f5 (diff)
Add math.Pow
Closes #7266
Diffstat (limited to 'tpl/math/math.go')
-rw-r--r--tpl/math/math.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/tpl/math/math.go b/tpl/math/math.go
index 950d95905..ecaf61ebc 100644
--- a/tpl/math/math.go
+++ b/tpl/math/math.go
@@ -115,6 +115,18 @@ func (ns *Namespace) Mul(a, b interface{}) (interface{}, error) {
return _math.DoArithmetic(a, b, '*')
}
+// Pow returns a raised to the power of b.
+func (ns *Namespace) Pow(a, b interface{}) (float64, error) {
+ af, erra := cast.ToFloat64E(a)
+ bf, errb := cast.ToFloat64E(b)
+
+ if erra != nil || errb != nil {
+ return 0, errors.New("Pow operator can't be used with non-float value")
+ }
+
+ return math.Pow(af, bf), nil
+}
+
// Round returns the nearest integer, rounding half away from zero.
func (ns *Namespace) Round(x interface{}) (float64, error) {
xf, err := cast.ToFloat64E(x)