Initial commit
This commit is contained in:
40
providers/math/math.go
Normal file
40
providers/math/math.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package math
|
||||
|
||||
import "math"
|
||||
import "html/template"
|
||||
import "git.tebibyte.media/sashakoshka/step"
|
||||
|
||||
var _ step.FuncProvider = new(Provider)
|
||||
|
||||
// Provider provides math functions.
|
||||
type Provider struct {
|
||||
|
||||
}
|
||||
|
||||
// FuncMap fulfills the step.FuncProvider interface.
|
||||
func (this *Provider) FuncMap () template.FuncMap {
|
||||
return template.FuncMap {
|
||||
"add": funcAdd,
|
||||
"sub": funcSub,
|
||||
"mul": funcMul,
|
||||
"div": funcDiv,
|
||||
"pow": math.Pow,
|
||||
"sqrt": math.Sqrt,
|
||||
}
|
||||
}
|
||||
|
||||
func funcAdd (a, b float64) float64 {
|
||||
return a + b
|
||||
}
|
||||
|
||||
func funcSub (a, b float64) float64 {
|
||||
return a - b
|
||||
}
|
||||
|
||||
func funcMul (a, b float64) float64 {
|
||||
return a * b
|
||||
}
|
||||
|
||||
func funcDiv (a, b float64) float64 {
|
||||
return a / b
|
||||
}
|
||||
Reference in New Issue
Block a user