package math

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

Package math provides template functions for mathematical operations.

Index

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

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

Abs returns the absolute value of n.

func (*Namespace) Acos

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

Acos returns the arccosine, in radians, of n.

func (*Namespace) Add

func (ns *Namespace) Add(inputs ...any) (any, error)

Add adds the multivalued addends n1 and n2 or more values.

func (*Namespace) Asin

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

Asin returns the arcsine, in radians, of n.

func (*Namespace) Atan

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

Atan returns the arctangent, in radians, of n.

func (*Namespace) Atan2

func (ns *Namespace) Atan2(n, m any) (float64, error)

Atan2 returns the arc tangent of n/m, using the signs of the two to determine the quadrant of the return value.

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

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

Cos returns the cosine of the radian argument 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. <docsmeta>{"identifiers": ["now.UnixNano"] }</docsmeta>

func (*Namespace) Div

func (ns *Namespace) Div(inputs ...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(inputs ...any) (maximum float64, err error)

Max returns the greater of all numbers in inputs. Any slices in inputs are flattened.

func (*Namespace) Min

func (ns *Namespace) Min(inputs ...any) (minimum float64, err error)

Min returns the smaller of all numbers in inputs. Any slices in inputs are flattened.

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(inputs ...any) (any, error)

Mul multiplies the multivalued numbers n1 and n2 or more values.

func (*Namespace) Pi

func (ns *Namespace) Pi() float64

Pi returns the mathematical constant pi.

func (*Namespace) Pow

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

Pow returns n1 raised to the power of n2.

func (*Namespace) Product

func (ns *Namespace) Product(inputs ...any) (product float64, err error)

Product returns the product of all numbers in inputs. Any slices in inputs are flattened.

func (*Namespace) Rand

func (ns *Namespace) Rand() float64

Rand returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).

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

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

Sin returns the sine of the radian argument n.

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(inputs ...any) (any, error)

Sub subtracts multivalued.

func (*Namespace) Sum

func (ns *Namespace) Sum(inputs ...any) (sum float64, err error)

Sum returns the sum of all numbers in inputs. Any slices in inputs are flattened.

func (*Namespace) Tan

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

Tan returns the tangent of the radian argument n.

func (*Namespace) ToDegrees

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

ToDegrees converts radians into degrees.

func (*Namespace) ToRadians

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

ToRadians converts degrees into radians.

Source Files

init.go math.go round.go

Version
v0.144.2 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
11 packages
Last checked
7 hours ago

Tools for package owners.