summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/math
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-27 10:48:33 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-27 10:48:57 +0100
commit5fd1e7490305570872d3899f5edda950903c5213 (patch)
treef0cdc490a0942d720494c0044a64c6397d1ab6a5 /docs/content/en/functions/math
parentfc7de7136acbcf0aef54ae8460c7702bc83709be (diff)
parent9b0050e9aabe4be65c78ccf292a348f309d50ccd (diff)
downloadhugo-5fd1e7490305570872d3899f5edda950903c5213.tar.gz
hugo-5fd1e7490305570872d3899f5edda950903c5213.zip
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
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/Rand.md46
-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.md24
-rw-r--r--docs/content/en/functions/math/Sum.md21
-rw-r--r--docs/content/en/functions/math/_index.md11
20 files changed, 410 insertions, 0 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/Rand.md b/docs/content/en/functions/math/Rand.md
new file mode 100644
index 000000000..4f71cfcdf
--- /dev/null
+++ b/docs/content/en/functions/math/Rand.md
@@ -0,0 +1,46 @@
+---
+title: math.Rand
+description: Returns a pseudo-random number in the half-open interval [0.0, 1.0).
+categories: []
+keywords: []
+action:
+ aliases: []
+ related: []
+ returnType: float64
+ signatures: [math.Rand]
+---
+
+{{< new-in 0.121.2 >}}
+
+The `math.Rand` function returns a pseudo-random number in the [half-open interval] [0.0, 1.0).
+
+```go-html-template
+{{ math.Rand }} → 0.6312770459590062
+```
+
+To generate a random integer in the [closed interval] [0, 5]:
+
+```go-html-template
+{{ math.Rand | mul 6 | math.Floor }}
+```
+
+To generate a random integer in the closed interval [1, 6]:
+
+```go-html-template
+{{ math.Rand | mul 6 | math.Ceil }}
+```
+
+To generate a random float, with one digit after the decimal point, in the closed interval [0, 4.9]:
+
+```go-html-template
+{{ div (math.Rand | mul 50 | math.Floor) 10 }}
+```
+
+To generate a random float, with one digit after the decimal point, in the closed interval [0.1, 5.0]:
+
+```go-html-template
+{{ div (math.Rand | mul 50 | math.Ceil) 10 }}
+```
+
+[closed interval]: /getting-started/glossary/#interval
+[half-open interval]: /getting-started/glossary/#interval
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..a89d0e69d
--- /dev/null
+++ b/docs/content/en/functions/math/Sub.md
@@ -0,0 +1,24 @@
+---
+title: math.Sub
+description: Subtracts one or more numbers from the first number.
+categories: []
+keywords: []
+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.