summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/math
diff options
context:
space:
mode:
Diffstat (limited to 'docs/content/en/functions/math')
-rw-r--r--docs/content/en/functions/math/Abs.md17
-rw-r--r--docs/content/en/functions/math/Add.md24
-rw-r--r--docs/content/en/functions/math/Ceil.md17
-rw-r--r--docs/content/en/functions/math/Counter.md35
-rw-r--r--docs/content/en/functions/math/Div.md24
-rw-r--r--docs/content/en/functions/math/Floor.md17
-rw-r--r--docs/content/en/functions/math/Log.md15
-rw-r--r--docs/content/en/functions/math/Max.md16
-rw-r--r--docs/content/en/functions/math/Min.md16
-rw-r--r--docs/content/en/functions/math/Mod.md16
-rw-r--r--docs/content/en/functions/math/ModBool.md16
-rw-r--r--docs/content/en/functions/math/Mul.md24
-rw-r--r--docs/content/en/functions/math/Pow.md16
-rw-r--r--docs/content/en/functions/math/Product.md22
-rw-r--r--docs/content/en/functions/math/Round.md17
-rw-r--r--docs/content/en/functions/math/Sqrt.md16
-rw-r--r--docs/content/en/functions/math/Sub.md23
-rw-r--r--docs/content/en/functions/math/Sum.md21
-rw-r--r--docs/content/en/functions/math/_index.md11
-rw-r--r--docs/content/en/functions/math/index.md39
20 files changed, 363 insertions, 39 deletions
diff --git a/docs/content/en/functions/math/Abs.md b/docs/content/en/functions/math/Abs.md
new file mode 100644
index 000000000..682b8426f
--- /dev/null
+++ b/docs/content/en/functions/math/Abs.md
@@ -0,0 +1,17 @@
+---
+title: math.Abs
+description: Returns the absolute value of the given number.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: float64
+ signatures: [math.Abs VALUE]
+---
+
+{{< new-in 0.112.0 >}}
+
+```go-html-template
+{{ math.Abs -2.1 }} → 2.1
+```
diff --git a/docs/content/en/functions/math/Add.md b/docs/content/en/functions/math/Add.md
new file mode 100644
index 000000000..afa8d48aa
--- /dev/null
+++ b/docs/content/en/functions/math/Add.md
@@ -0,0 +1,24 @@
+---
+title: math.Add
+description: Adds two or more numbers.
+categories: []
+keywords: []
+action:
+ aliases: [add]
+ related:
+ - functions/math/Div
+ - functions/math/Mul
+ - functions/math/Product
+ - functions/math/Sub
+ - functions/math/Sum
+ returnType: any
+ signatures: [math.Add VALUE VALUE...]
+---
+
+If one of the numbers is a [`float`], the result is a `float`.
+
+```go-html-template
+{{ add 12 3 2 }} → 17
+```
+
+[`float`]: /getting-started/glossary/#float
diff --git a/docs/content/en/functions/math/Ceil.md b/docs/content/en/functions/math/Ceil.md
new file mode 100644
index 000000000..9f74991c3
--- /dev/null
+++ b/docs/content/en/functions/math/Ceil.md
@@ -0,0 +1,17 @@
+---
+title: math.Ceil
+description: Returns the least integer value greater than or equal to the given number.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Floor
+ - functions/math/Round
+ returnType: float64
+ signatures: [math.Ceil VALUE]
+---
+
+```go-html-template
+{{ math.Ceil 2.1 }} → 3
+```
diff --git a/docs/content/en/functions/math/Counter.md b/docs/content/en/functions/math/Counter.md
new file mode 100644
index 000000000..7f53bdd0c
--- /dev/null
+++ b/docs/content/en/functions/math/Counter.md
@@ -0,0 +1,35 @@
+---
+title: math.Counter
+description: Increments and returns a global counter.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: uint64
+ signatures: [math.Counter]
+---
+
+The counter is global for both monolingual and multilingual sites, and its initial value for each build is&nbsp;1.
+
+```go-html-template
+{{ warnf "single.html called %d times" math.Counter }}
+```
+
+```sh
+WARN single.html called 1 times
+WARN single.html called 2 times
+WARN single.html called 3 times
+```
+
+Use this function to:
+
+- Create unique warnings as shown above; the [`warnf`] function suppresses duplicate messages
+- Create unique target paths for the `resources.FromString` function where the target path is also the cache key
+
+[`warnf`]: /functions/fmt/warnf
+[`resources.FromString`]: /functions/resources/fromstring
+
+{{% note %}}
+Due to concurrency, the value returned in a given template for a given page will vary from one build to the next. You cannot use this function to assign a static id to each page.
+{{% /note %}}
diff --git a/docs/content/en/functions/math/Div.md b/docs/content/en/functions/math/Div.md
new file mode 100644
index 000000000..530474a78
--- /dev/null
+++ b/docs/content/en/functions/math/Div.md
@@ -0,0 +1,24 @@
+---
+title: math.Div
+description: Divides the first number by one or more numbers.
+categories: []
+keywords: []
+action:
+ aliases: [div]
+ related:
+ - functions/math/Add
+ - functions/math/Mul
+ - functions/math/Product
+ - functions/math/Sub
+ - functions/math/Sum
+ returnType: any
+ signatures: [math.Div VALUE VALUE...]
+---
+
+If one of the numbers is a [`float`], the result is a `float`.
+
+```go-html-template
+{{ div 12 3 2 }} → 2
+```
+
+[`float`]: /getting-started/glossary/#float
diff --git a/docs/content/en/functions/math/Floor.md b/docs/content/en/functions/math/Floor.md
new file mode 100644
index 000000000..10ad758b6
--- /dev/null
+++ b/docs/content/en/functions/math/Floor.md
@@ -0,0 +1,17 @@
+---
+title: math.Floor
+description: Returns the greatest integer value less than or equal to the given number.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Ceil
+ - functions/math/Round
+ returnType: float64
+ signatures: [math.Floor VALUE]
+---
+
+```go-html-template
+{{ math.Floor 1.9 }} → 1
+```
diff --git a/docs/content/en/functions/math/Log.md b/docs/content/en/functions/math/Log.md
new file mode 100644
index 000000000..84edcb288
--- /dev/null
+++ b/docs/content/en/functions/math/Log.md
@@ -0,0 +1,15 @@
+---
+title: math.Log
+description: Returns the natural logarithm of the given number.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: float64
+ signatures: [math.Log VALUE]
+---
+
+```go-html-template
+{{ math.Log 42 }} → 3.737
+```
diff --git a/docs/content/en/functions/math/Max.md b/docs/content/en/functions/math/Max.md
new file mode 100644
index 000000000..9beff5630
--- /dev/null
+++ b/docs/content/en/functions/math/Max.md
@@ -0,0 +1,16 @@
+---
+title: math.Max
+description: Returns the greater of all numbers. Accepts scalars, slices, or both.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Min
+ returnType: float64
+ signatures: [math.Max VALUE...]
+---
+
+```go-html-template
+{{ math.Max 1 (slice 2 3) 4 }} → 4
+```
diff --git a/docs/content/en/functions/math/Min.md b/docs/content/en/functions/math/Min.md
new file mode 100644
index 000000000..79e464c74
--- /dev/null
+++ b/docs/content/en/functions/math/Min.md
@@ -0,0 +1,16 @@
+---
+title: math.Min
+description: Returns the smaller of all numbers. Accepts scalars, slices, or both.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Max
+ returnType: float64
+ signatures: [math.Min VALUE...]
+---
+
+```go-html-template
+{{ math.Min 1 (slice 2 3) 4 }} → 1
+```
diff --git a/docs/content/en/functions/math/Mod.md b/docs/content/en/functions/math/Mod.md
new file mode 100644
index 000000000..d312730c5
--- /dev/null
+++ b/docs/content/en/functions/math/Mod.md
@@ -0,0 +1,16 @@
+---
+title: math.Mod
+description: Returns the modulus of two integers.
+categories: []
+keywords: []
+action:
+ aliases: [mod]
+ related:
+ - functions/math/ModBool
+ returnType: int64
+ signatures: [math.Mod VALUE1 VALUE2]
+---
+
+```go-html-template
+{{ mod 15 3 }} → 0
+```
diff --git a/docs/content/en/functions/math/ModBool.md b/docs/content/en/functions/math/ModBool.md
new file mode 100644
index 000000000..d915ff614
--- /dev/null
+++ b/docs/content/en/functions/math/ModBool.md
@@ -0,0 +1,16 @@
+---
+title: math.ModBool
+description: Reports whether the modulus of two integers equals 0.
+categories: []
+keywords: []
+action:
+ aliases: [modBool]
+ related:
+ - functions/math/Mod
+ returnType: bool
+ signatures: [math.ModBool VALUE1 VALUE2]
+---
+
+```go-html-template
+{{ modBool 15 3 }} → true
+```
diff --git a/docs/content/en/functions/math/Mul.md b/docs/content/en/functions/math/Mul.md
new file mode 100644
index 000000000..6824599e3
--- /dev/null
+++ b/docs/content/en/functions/math/Mul.md
@@ -0,0 +1,24 @@
+---
+title: math.Mul
+description: Multiplies two or more numbers.
+categories: []
+keywords: []
+action:
+ aliases: [mul]
+ related:
+ - functions/math/Add
+ - functions/math/Div
+ - functions/math/Product
+ - functions/math/Sub
+ - functions/math/Sum
+ returnType: any
+ signatures: [math.Mul VALUE VALUE...]
+---
+
+If one of the numbers is a [`float`], the result is a `float`.
+
+```go-html-template
+{{ mul 12 3 2 }} → 72
+```
+
+[`float`]: /getting-started/glossary/#float
diff --git a/docs/content/en/functions/math/Pow.md b/docs/content/en/functions/math/Pow.md
new file mode 100644
index 000000000..5a1482d73
--- /dev/null
+++ b/docs/content/en/functions/math/Pow.md
@@ -0,0 +1,16 @@
+---
+title: math.Pow
+description: Returns the first number raised to the power of the second number.
+categories: []
+keywords: []
+action:
+ aliases: [pow]
+ related:
+ - functions/math/Sqrt
+ returnType: float64
+ signatures: [math.Pow VALUE1 VALUE2]
+---
+
+```go-html-template
+{{ math.Pow 2 3 }} → 8
+```
diff --git a/docs/content/en/functions/math/Product.md b/docs/content/en/functions/math/Product.md
new file mode 100644
index 000000000..d94df4f1b
--- /dev/null
+++ b/docs/content/en/functions/math/Product.md
@@ -0,0 +1,22 @@
+---
+title: math.Product
+description: Returns the product of all numbers. Accepts scalars, slices, or both.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Add
+ - functions/math/Div
+ - functions/math/Mul
+ - functions/math/Sub
+ - functions/math/Sum
+ returnType: float64
+ signatures: [math.Product VALUE...]
+---
+
+{{< new-in 0.114.0 >}}
+
+```go-html-template
+{{ math.Product 1 (slice 2 3) 4 }} → 24
+```
diff --git a/docs/content/en/functions/math/Round.md b/docs/content/en/functions/math/Round.md
new file mode 100644
index 000000000..e0678eb78
--- /dev/null
+++ b/docs/content/en/functions/math/Round.md
@@ -0,0 +1,17 @@
+---
+title: math.Round
+description: Returns the nearest integer, rounding half away from zero.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Ceil
+ - functions/math/Floor
+ returnType: float64
+ signatures: [math.Round VALUE]
+---
+
+```go-html-template
+{{ math.Round 1.5 }} → 2
+```
diff --git a/docs/content/en/functions/math/Sqrt.md b/docs/content/en/functions/math/Sqrt.md
new file mode 100644
index 000000000..436cb31c3
--- /dev/null
+++ b/docs/content/en/functions/math/Sqrt.md
@@ -0,0 +1,16 @@
+---
+title: math.Sqrt
+description: Returns the square root of the given number.
+categories: []
+keywords: []
+action:
+ aliases: []
+ related:
+ - functions/math/Pow
+ returnType: float64
+ signatures: [math.Sqrt VALUE]
+---
+
+```go-html-template
+{{ math.Sqrt 81 }} → 9
+```
diff --git a/docs/content/en/functions/math/Sub.md b/docs/content/en/functions/math/Sub.md
new file mode 100644
index 000000000..2865ac191
--- /dev/null
+++ b/docs/content/en/functions/math/Sub.md
@@ -0,0 +1,23 @@
+---
+title: math.Sub
+description: Subtracts one or more numbers from the first number.
+categories: []
+action:
+ aliases: [sub]
+ related:
+ - functions/math/Add
+ - functions/math/Div
+ - functions/math/Mul
+ - functions/math/Product
+ - functions/math/Sum
+ returnType: any
+ signatures: [math.Sub VALUE VALUE...]
+---
+
+If one of the numbers is a [`float`], the result is a `float`.
+
+```go-html-template
+{{ sub 12 3 2 }} → 7
+```
+
+[`float`]: /getting-started/glossary/#float
diff --git a/docs/content/en/functions/math/Sum.md b/docs/content/en/functions/math/Sum.md
new file mode 100644
index 000000000..eba03f72d
--- /dev/null
+++ b/docs/content/en/functions/math/Sum.md
@@ -0,0 +1,21 @@
+---
+title: math.Sum
+description: Returns the sum of all numbers. Accepts scalars, slices, or both.
+categories: []
+action:
+ aliases: []
+ related:
+ - functions/math/Add
+ - functions/math/Div
+ - functions/math/Mul
+ - functions/math/Product
+ - functions/math/Sub
+ returnType: float64
+ signatures: [math.Sum VALUE...]
+---
+
+{{< new-in 0.114.0 >}}
+
+```go-html-template
+{{ math.Sum 1 (slice 2 3) 4 }} → 10
+```
diff --git a/docs/content/en/functions/math/_index.md b/docs/content/en/functions/math/_index.md
new file mode 100644
index 000000000..76713bc99
--- /dev/null
+++ b/docs/content/en/functions/math/_index.md
@@ -0,0 +1,11 @@
+---
+title: Math functions
+linkTitle: math
+description: Template functions to perform mathematical operations.
+categories: []
+menu:
+ docs:
+ parent: functions
+---
+
+Use these functions to perform mathematical operations.
diff --git a/docs/content/en/functions/math/index.md b/docs/content/en/functions/math/index.md
deleted file mode 100644
index fd4d10a31..000000000
--- a/docs/content/en/functions/math/index.md
+++ /dev/null
@@ -1,39 +0,0 @@
----
-title: math
-description: Hugo provides mathematical operators in templates.
-categories: [functions]
-keywords: []
-
-menu:
- docs:
- parent: functions
-function:
- aliases: []
- returnType:
- signatures: []
-relatedFunctions: []
----
-
-| Function | Description | Example |
-|-----------------|-----------------------------------------------------------------------------|---------------------------------------------------|
-| `add` | Adds two or more numbers. | `{{ add 12 3 2 }}` &rarr; `17` |
-| | *If one of the numbers is a float, the result is a float.* | `{{ add 1.1 2 }}` &rarr; `3.1` |
-| `sub` | Subtracts one or more numbers from the first number. | `{{ sub 12 3 2 }}` &rarr; `7` |
-| | *If one of the numbers is a float, the result is a float.* | `{{ sub 3 2.5 }}` &rarr; `0.5` |
-| `mul` | Multiplies two or more numbers. | `{{ mul 12 3 2 }}` &rarr; `72` |
-| | *If one of the numbers is a float, the result is a float.* | `{{ mul 2 3.1 }}` &rarr; `6.2` |
-| `div` | Divides the first number by one or more numbers. | `{{ div 12 3 2 }}` &rarr; `2` |
-| | *If one of the numbers is a float, the result is a float.* | `{{ div 6 4.0 }}` &rarr; `1.5` |
-| `mod` | Modulus of two integers. | `{{ mod 15 3 }}` &rarr; `0` |
-| `modBool` | Boolean of modulus of two integers. Evaluates to `true` if result equals 0. | `{{ modBool 15 3 }}` &rarr; `true` |
-| `math.Abs` | Returns the absolute value of the given number. | `{{ math.Abs -2.1 }}` &rarr; `2.1` |
-| `math.Ceil` | Returns the least integer value greater than or equal to the given number. | `{{ math.Ceil 2.1 }}` &rarr; `3` |
-| `math.Floor` | Returns the greatest integer value less than or equal to the given number. | `{{ math.Floor 1.9 }}` &rarr; `1` |
-| `math.Log` | Returns the natural logarithm of the given number. | `{{ math.Log 42 }}` &rarr; `3.737` |
-| `math.Max` | Returns the greater of all numbers. Accepts scalars, slices, or both. | `{{ math.Max 1 (slice 2 3) 4 }}` &rarr; `4` |
-| `math.Min` | Returns the smaller of all numbers. Accepts scalars, slices, or both. | `{{ math.Min 1 (slice 2 3) 4 }}` &rarr; `1` |
-| `math.Product` | Returns the product of all numbers. Accepts scalars, slices, or both. | `{{ math.Product 1 (slice 2 3) 4 }}` &rarr; `24` |
-| `math.Pow` | Returns the first number raised to the power of the second number. | `{{ math.Pow 2 3 }}` &rarr; `8` |
-| `math.Round` | Returns the nearest integer, rounding half away from zero. | `{{ math.Round 1.5 }}` &rarr; `2` |
-| `math.Sqrt` | Returns the square root of the given number. | `{{ math.Sqrt 81 }}` &rarr; `9` |
-| `math.Sum` | Returns the sum of all numbers. Accepts scalars, slices, or both. | `{{ math.Sum 1 (slice 2 3) 4 }}` &rarr; `10` |