mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
17
docs/content/en/functions/math/Abs.md
Normal file
17
docs/content/en/functions/math/Abs.md
Normal file
@@ -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
|
||||
```
|
24
docs/content/en/functions/math/Add.md
Normal file
24
docs/content/en/functions/math/Add.md
Normal file
@@ -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
|
17
docs/content/en/functions/math/Ceil.md
Normal file
17
docs/content/en/functions/math/Ceil.md
Normal file
@@ -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
|
||||
```
|
35
docs/content/en/functions/math/Counter.md
Normal file
35
docs/content/en/functions/math/Counter.md
Normal file
@@ -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 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 %}}
|
24
docs/content/en/functions/math/Div.md
Normal file
24
docs/content/en/functions/math/Div.md
Normal file
@@ -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
|
17
docs/content/en/functions/math/Floor.md
Normal file
17
docs/content/en/functions/math/Floor.md
Normal file
@@ -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
|
||||
```
|
15
docs/content/en/functions/math/Log.md
Normal file
15
docs/content/en/functions/math/Log.md
Normal file
@@ -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
|
||||
```
|
16
docs/content/en/functions/math/Max.md
Normal file
16
docs/content/en/functions/math/Max.md
Normal file
@@ -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
|
||||
```
|
16
docs/content/en/functions/math/Min.md
Normal file
16
docs/content/en/functions/math/Min.md
Normal file
@@ -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
|
||||
```
|
16
docs/content/en/functions/math/Mod.md
Normal file
16
docs/content/en/functions/math/Mod.md
Normal file
@@ -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
|
||||
```
|
16
docs/content/en/functions/math/ModBool.md
Normal file
16
docs/content/en/functions/math/ModBool.md
Normal file
@@ -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
|
||||
```
|
24
docs/content/en/functions/math/Mul.md
Normal file
24
docs/content/en/functions/math/Mul.md
Normal file
@@ -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
|
16
docs/content/en/functions/math/Pow.md
Normal file
16
docs/content/en/functions/math/Pow.md
Normal file
@@ -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
|
||||
```
|
22
docs/content/en/functions/math/Product.md
Normal file
22
docs/content/en/functions/math/Product.md
Normal file
@@ -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
|
||||
```
|
17
docs/content/en/functions/math/Round.md
Normal file
17
docs/content/en/functions/math/Round.md
Normal file
@@ -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
|
||||
```
|
16
docs/content/en/functions/math/Sqrt.md
Normal file
16
docs/content/en/functions/math/Sqrt.md
Normal file
@@ -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
|
||||
```
|
23
docs/content/en/functions/math/Sub.md
Normal file
23
docs/content/en/functions/math/Sub.md
Normal file
@@ -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
|
21
docs/content/en/functions/math/Sum.md
Normal file
21
docs/content/en/functions/math/Sum.md
Normal file
@@ -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
|
||||
```
|
11
docs/content/en/functions/math/_index.md
Normal file
11
docs/content/en/functions/math/_index.md
Normal file
@@ -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.
|
@@ -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 }}` → `17` |
|
||||
| | *If one of the numbers is a float, the result is a float.* | `{{ add 1.1 2 }}` → `3.1` |
|
||||
| `sub` | Subtracts one or more numbers from the first number. | `{{ sub 12 3 2 }}` → `7` |
|
||||
| | *If one of the numbers is a float, the result is a float.* | `{{ sub 3 2.5 }}` → `0.5` |
|
||||
| `mul` | Multiplies two or more numbers. | `{{ mul 12 3 2 }}` → `72` |
|
||||
| | *If one of the numbers is a float, the result is a float.* | `{{ mul 2 3.1 }}` → `6.2` |
|
||||
| `div` | Divides the first number by one or more numbers. | `{{ div 12 3 2 }}` → `2` |
|
||||
| | *If one of the numbers is a float, the result is a float.* | `{{ div 6 4.0 }}` → `1.5` |
|
||||
| `mod` | Modulus of two integers. | `{{ mod 15 3 }}` → `0` |
|
||||
| `modBool` | Boolean of modulus of two integers. Evaluates to `true` if result equals 0. | `{{ modBool 15 3 }}` → `true` |
|
||||
| `math.Abs` | Returns the absolute value of the given number. | `{{ math.Abs -2.1 }}` → `2.1` |
|
||||
| `math.Ceil` | Returns the least integer value greater than or equal to the given number. | `{{ math.Ceil 2.1 }}` → `3` |
|
||||
| `math.Floor` | Returns the greatest integer value less than or equal to the given number. | `{{ math.Floor 1.9 }}` → `1` |
|
||||
| `math.Log` | Returns the natural logarithm of the given number. | `{{ math.Log 42 }}` → `3.737` |
|
||||
| `math.Max` | Returns the greater of all numbers. Accepts scalars, slices, or both. | `{{ math.Max 1 (slice 2 3) 4 }}` → `4` |
|
||||
| `math.Min` | Returns the smaller of all numbers. Accepts scalars, slices, or both. | `{{ math.Min 1 (slice 2 3) 4 }}` → `1` |
|
||||
| `math.Product` | Returns the product of all numbers. Accepts scalars, slices, or both. | `{{ math.Product 1 (slice 2 3) 4 }}` → `24` |
|
||||
| `math.Pow` | Returns the first number raised to the power of the second number. | `{{ math.Pow 2 3 }}` → `8` |
|
||||
| `math.Round` | Returns the nearest integer, rounding half away from zero. | `{{ math.Round 1.5 }}` → `2` |
|
||||
| `math.Sqrt` | Returns the square root of the given number. | `{{ math.Sqrt 81 }}` → `9` |
|
||||
| `math.Sum` | Returns the sum of all numbers. Accepts scalars, slices, or both. | `{{ math.Sum 1 (slice 2 3) 4 }}` → `10` |
|
Reference in New Issue
Block a user