package math

import "github.com/gohugoio/hugo/tpl/math"

Package math provides template functions for mathematical operations.

Index

Package Files

init.go math.go round.go

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) Add

func (ns *Namespace) Add(n1, n2 any) (any, error)

Add adds the two addends n1 and n2.

func (*Namespace) Ceil

func (ns *Namespace) Ceil(n any) (float64, error)

Ceil returns the least integer value greater than or equal to n.

func (*Namespace) Counter

func (ns *Namespace) Counter() uint64

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.

func (*Namespace) Div

func (ns *Namespace) Div(n1, n2 any) (any, error)

Div divides n1 by n2.

func (*Namespace) Floor

func (ns *Namespace) Floor(n any) (float64, error)

Floor returns the greatest integer value less than or equal to n.

func (*Namespace) Log

func (ns *Namespace) Log(n any) (float64, error)

Log returns the natural logarithm of the number n.

func (*Namespace) Max

func (ns *Namespace) Max(n1, n2 any) (float64, error)

Max returns the greater of the two numbers n1 or n2.

func (*Namespace) Min

func (ns *Namespace) Min(n1, n2 any) (float64, error)

Min returns the smaller of two numbers n1 or n2.

func (*Namespace) Mod

func (ns *Namespace) Mod(n1, n2 any) (int64, error)

Mod returns n1 % n2.

func (*Namespace) ModBool

func (ns *Namespace) ModBool(n1, n2 any) (bool, error)

ModBool returns the boolean of n1 % n2. If n1 % n2 == 0, return true.

func (*Namespace) Mul

func (ns *Namespace) Mul(n1, n2 any) (any, error)

Mul multiplies the two numbers n1 and n2.

func (*Namespace) Pow

func (ns *Namespace) Pow(n1, n2 any) (float64, error)

Pow returns n1 raised to the power of n2.

func (*Namespace) Round

func (ns *Namespace) Round(n any) (float64, error)

Round returns the integer nearest to n, rounding half away from zero.

func (*Namespace) Sqrt

func (ns *Namespace) Sqrt(n any) (float64, error)

Sqrt returns the square root of the number n.

func (*Namespace) Sub

func (ns *Namespace) Sub(n1, n2 any) (any, error)

Sub subtracts n2 from n1.

Version
v0.101.0 (latest)
Published
Jun 16, 2022
Platform
linux/amd64
Imports
7 packages (graph)
Last checked
3 hours ago

Tools for package owners.