package math
import "github.com/gohugoio/hugo/tpl/math"
Package math provides template functions for mathematical operations.
Index ¶
- type Namespace
- func New() *Namespace
- func (ns *Namespace) Abs(n any) (float64, error)
- func (ns *Namespace) Add(inputs ...any) (any, error)
- func (ns *Namespace) Ceil(n any) (float64, error)
- func (ns *Namespace) Counter() uint64
- func (ns *Namespace) Div(inputs ...any) (any, error)
- func (ns *Namespace) Floor(n any) (float64, error)
- func (ns *Namespace) Log(n any) (float64, error)
- func (ns *Namespace) Max(inputs ...any) (maximum float64, err error)
- func (ns *Namespace) Min(inputs ...any) (minimum float64, err error)
- func (ns *Namespace) Mod(n1, n2 any) (int64, error)
- func (ns *Namespace) ModBool(n1, n2 any) (bool, error)
- func (ns *Namespace) Mul(inputs ...any) (any, error)
- func (ns *Namespace) Pow(n1, n2 any) (float64, error)
- func (ns *Namespace) Product(inputs ...any) (product float64, err error)
- func (ns *Namespace) Rand() float64
- func (ns *Namespace) Round(n any) (float64, error)
- func (ns *Namespace) Sqrt(n any) (float64, error)
- func (ns *Namespace) Sub(inputs ...any) (any, error)
- func (ns *Namespace) Sum(inputs ...any) (sum float64, err error)
Types ¶
type Namespace ¶
type Namespace struct{}
Namespace provides template functions for the "math" namespace.
func New ¶
func New() *Namespace
New returns a new instance of the math-namespaced template functions.
func (*Namespace) Abs ¶
Abs returns the absolute value of n.
func (*Namespace) Add ¶
Add adds the multivalued addends n1 and n2 or more values.
func (*Namespace) Ceil ¶
Ceil returns the least integer value greater than or equal to n.
func (*Namespace) Counter ¶
Counter increments and returns a global counter. This was originally added to be used in tests where now.UnixNano did not have the needed precision (especially on Windows). Note that given the parallel nature of Hugo, you cannot use this to get sequences of numbers, and the counter will reset on new builds. <docsmeta>{"identifiers": ["now.UnixNano"] }</docsmeta>
func (*Namespace) Div ¶
Div divides n1 by n2.
func (*Namespace) Floor ¶
Floor returns the greatest integer value less than or equal to n.
func (*Namespace) Log ¶
Log returns the natural logarithm of the number n.
func (*Namespace) Max ¶
Max returns the greater of all numbers in inputs. Any slices in inputs are flattened.
func (*Namespace) Min ¶
Min returns the smaller of all numbers in inputs. Any slices in inputs are flattened.
func (*Namespace) Mod ¶
Mod returns n1 % n2.
func (*Namespace) ModBool ¶
ModBool returns the boolean of n1 % n2. If n1 % n2 == 0, return true.
func (*Namespace) Mul ¶
Mul multiplies the multivalued numbers n1 and n2 or more values.
func (*Namespace) Pow ¶
Pow returns n1 raised to the power of n2.
func (*Namespace) Product ¶
Product returns the product of all numbers in inputs. Any slices in inputs are flattened.
func (*Namespace) Rand ¶
Rand returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).
func (*Namespace) Round ¶
Round returns the integer nearest to n, rounding half away from zero.
func (*Namespace) Sqrt ¶
Sqrt returns the square root of the number n.
func (*Namespace) Sub ¶
Sub subtracts multivalued.
func (*Namespace) Sum ¶
Sum returns the sum of all numbers in inputs. Any slices in inputs are flattened.
Source Files ¶
- Version
- v0.127.0
- Published
- Jun 5, 2024
- Platform
- js/wasm
- Imports
- 11 packages
- Last checked
- 31 minutes ago –
Tools for package owners.