diff options
Diffstat (limited to 'docs/content/en/functions/math')
30 files changed, 520 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..60d8d6d64 --- /dev/null +++ b/docs/content/en/functions/math/Abs.md @@ -0,0 +1,15 @@ +--- +title: math.Abs +description: Returns the absolute value of the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Abs VALUE] +--- + +```go-html-template +{{ math.Abs -2.1 }} → 2.1 +``` diff --git a/docs/content/en/functions/math/Acos.md b/docs/content/en/functions/math/Acos.md new file mode 100644 index 000000000..32537e2dd --- /dev/null +++ b/docs/content/en/functions/math/Acos.md @@ -0,0 +1,17 @@ +--- +title: math.Acos +description: Returns the arccosine, in radians, of the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Acos VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Acos 1 }} → 0 +``` diff --git a/docs/content/en/functions/math/Add.md b/docs/content/en/functions/math/Add.md new file mode 100644 index 000000000..cd137c6c7 --- /dev/null +++ b/docs/content/en/functions/math/Add.md @@ -0,0 +1,23 @@ +--- +title: math.Add +description: Adds two or more numbers. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [add] + returnType: any + signatures: [math.Add VALUE VALUE...] +--- + +If one of the numbers is a [`float`](g), the result is a `float`. + +```go-html-template +{{ add 12 3 2 }} → 17 +``` + +You can also use the `add` function to concatenate strings. + +```go-html-template +{{ add "hu" "go" }} → hugo +``` diff --git a/docs/content/en/functions/math/Asin.md b/docs/content/en/functions/math/Asin.md new file mode 100644 index 000000000..76114a72e --- /dev/null +++ b/docs/content/en/functions/math/Asin.md @@ -0,0 +1,17 @@ +--- +title: math.Asin +description: Returns the arcsine, in radians, of the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Asin VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Asin 1 }} → 1.5707963267948966 +``` diff --git a/docs/content/en/functions/math/Atan.md b/docs/content/en/functions/math/Atan.md new file mode 100644 index 000000000..5c8268b47 --- /dev/null +++ b/docs/content/en/functions/math/Atan.md @@ -0,0 +1,17 @@ +--- +title: math.Atan +description: Returns the arctangent, in radians, of the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Atan VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Atan 1 }} → 0.7853981633974483 +``` diff --git a/docs/content/en/functions/math/Atan2.md b/docs/content/en/functions/math/Atan2.md new file mode 100644 index 000000000..942fffdf8 --- /dev/null +++ b/docs/content/en/functions/math/Atan2.md @@ -0,0 +1,17 @@ +--- +title: math.Atan2 +description: Returns the arctangent, in radians, of the given number pair, determining the correct quadrant from their signs. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Atan2 VALUE VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Atan2 1 2 }} → 0.4636476090008061 +``` diff --git a/docs/content/en/functions/math/Ceil.md b/docs/content/en/functions/math/Ceil.md new file mode 100644 index 000000000..22a9d0299 --- /dev/null +++ b/docs/content/en/functions/math/Ceil.md @@ -0,0 +1,15 @@ +--- +title: math.Ceil +description: Returns the least integer value greater than or equal to the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Ceil VALUE] +--- + +```go-html-template +{{ math.Ceil 2.1 }} → 3 +``` diff --git a/docs/content/en/functions/math/Cos.md b/docs/content/en/functions/math/Cos.md new file mode 100644 index 000000000..249a064bb --- /dev/null +++ b/docs/content/en/functions/math/Cos.md @@ -0,0 +1,17 @@ +--- +title: math.Cos +description: Returns the cosine of the given radian number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Cos VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Cos 1 }} → 0.5403023058681398 +``` diff --git a/docs/content/en/functions/math/Counter.md b/docs/content/en/functions/math/Counter.md new file mode 100644 index 000000000..16456cec6 --- /dev/null +++ b/docs/content/en/functions/math/Counter.md @@ -0,0 +1,33 @@ +--- +title: math.Counter +description: Increments and returns a global counter. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + 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 + +> [!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. + +[`warnf`]: /functions/fmt/warnf/ diff --git a/docs/content/en/functions/math/Div.md b/docs/content/en/functions/math/Div.md new file mode 100644 index 000000000..0e338a9e9 --- /dev/null +++ b/docs/content/en/functions/math/Div.md @@ -0,0 +1,17 @@ +--- +title: math.Div +description: Divides the first number by one or more numbers. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [div] + returnType: any + signatures: [math.Div VALUE VALUE...] +--- + +If one of the numbers is a [`float`](g), the result is a `float`. + +```go-html-template +{{ div 12 3 2 }} → 2 +``` diff --git a/docs/content/en/functions/math/Floor.md b/docs/content/en/functions/math/Floor.md new file mode 100644 index 000000000..dbfd8620e --- /dev/null +++ b/docs/content/en/functions/math/Floor.md @@ -0,0 +1,15 @@ +--- +title: math.Floor +description: Returns the greatest integer value less than or equal to the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + 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..123ffacd7 --- /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: [] +params: + functions_and_methods: + aliases: [] + 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..d3a7676fc --- /dev/null +++ b/docs/content/en/functions/math/Max.md @@ -0,0 +1,15 @@ +--- +title: math.Max +description: Returns the greater of all numbers. Accepts scalars, slices, or both. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + 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..4f7d7b85a --- /dev/null +++ b/docs/content/en/functions/math/Min.md @@ -0,0 +1,15 @@ +--- +title: math.Min +description: Returns the smaller of all numbers. Accepts scalars, slices, or both. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + 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..6035a361e --- /dev/null +++ b/docs/content/en/functions/math/Mod.md @@ -0,0 +1,15 @@ +--- +title: math.Mod +description: Returns the modulus of two integers. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [mod] + 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..fc7813d67 --- /dev/null +++ b/docs/content/en/functions/math/ModBool.md @@ -0,0 +1,15 @@ +--- +title: math.ModBool +description: Reports whether the modulus of two integers equals 0. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [modBool] + 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..69f2dbe1b --- /dev/null +++ b/docs/content/en/functions/math/Mul.md @@ -0,0 +1,17 @@ +--- +title: math.Mul +description: Multiplies two or more numbers. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [mul] + returnType: any + signatures: [math.Mul VALUE VALUE...] +--- + +If one of the numbers is a [`float`](g), the result is a `float`. + +```go-html-template +{{ mul 12 3 2 }} → 72 +``` diff --git a/docs/content/en/functions/math/Pi.md b/docs/content/en/functions/math/Pi.md new file mode 100644 index 000000000..0bc74bf03 --- /dev/null +++ b/docs/content/en/functions/math/Pi.md @@ -0,0 +1,17 @@ +--- +title: math.Pi +description: Returns the mathematical constant pi. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Pi] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Pi }} → 3.141592653589793 +``` diff --git a/docs/content/en/functions/math/Pow.md b/docs/content/en/functions/math/Pow.md new file mode 100644 index 000000000..a4384305d --- /dev/null +++ b/docs/content/en/functions/math/Pow.md @@ -0,0 +1,15 @@ +--- +title: math.Pow +description: Returns the first number raised to the power of the second number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [pow] + 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..ffb1afe46 --- /dev/null +++ b/docs/content/en/functions/math/Product.md @@ -0,0 +1,15 @@ +--- +title: math.Product +description: Returns the product of all numbers. Accepts scalars, slices, or both. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Product VALUE...] +--- + +```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..d659e651f --- /dev/null +++ b/docs/content/en/functions/math/Rand.md @@ -0,0 +1,43 @@ +--- +title: math.Rand +description: Returns a pseudo-random number in the half-open interval [0.0, 1.0). +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Rand] +--- + +{{< new-in 0.121.2 />}} + +The `math.Rand` function returns a pseudo-random number in the half-open [interval](g) [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 }} +``` diff --git a/docs/content/en/functions/math/Round.md b/docs/content/en/functions/math/Round.md new file mode 100644 index 000000000..6bc015ce7 --- /dev/null +++ b/docs/content/en/functions/math/Round.md @@ -0,0 +1,15 @@ +--- +title: math.Round +description: Returns the nearest integer, rounding half away from zero. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Round VALUE] +--- + +```go-html-template +{{ math.Round 1.5 }} → 2 +``` diff --git a/docs/content/en/functions/math/Sin.md b/docs/content/en/functions/math/Sin.md new file mode 100644 index 000000000..b5ab86bb8 --- /dev/null +++ b/docs/content/en/functions/math/Sin.md @@ -0,0 +1,17 @@ +--- +title: math.Sin +description: Returns the sine of the given radian number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Sin VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Sin 1 }} → 0.8414709848078965 +``` diff --git a/docs/content/en/functions/math/Sqrt.md b/docs/content/en/functions/math/Sqrt.md new file mode 100644 index 000000000..b2f49fdbd --- /dev/null +++ b/docs/content/en/functions/math/Sqrt.md @@ -0,0 +1,15 @@ +--- +title: math.Sqrt +description: Returns the square root of the given number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + 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..49459cd71 --- /dev/null +++ b/docs/content/en/functions/math/Sub.md @@ -0,0 +1,17 @@ +--- +title: math.Sub +description: Subtracts one or more numbers from the first number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [sub] + returnType: any + signatures: [math.Sub VALUE VALUE...] +--- + +If one of the numbers is a [`float`](g), the result is a `float`. + +```go-html-template +{{ sub 12 3 2 }} → 7 +``` diff --git a/docs/content/en/functions/math/Sum.md b/docs/content/en/functions/math/Sum.md new file mode 100644 index 000000000..e14bc924b --- /dev/null +++ b/docs/content/en/functions/math/Sum.md @@ -0,0 +1,14 @@ +--- +title: math.Sum +description: Returns the sum of all numbers. Accepts scalars, slices, or both. +categories: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Sum VALUE...] +--- + +```go-html-template +{{ math.Sum 1 (slice 2 3) 4 }} → 10 +``` diff --git a/docs/content/en/functions/math/Tan.md b/docs/content/en/functions/math/Tan.md new file mode 100644 index 000000000..c4f861c05 --- /dev/null +++ b/docs/content/en/functions/math/Tan.md @@ -0,0 +1,17 @@ +--- +title: math.Tan +description: Returns the tangent of the given radian number. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.Tan VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.Tan 1 }} → 1.557407724654902 +``` diff --git a/docs/content/en/functions/math/ToDegrees.md b/docs/content/en/functions/math/ToDegrees.md new file mode 100644 index 000000000..f01cd4728 --- /dev/null +++ b/docs/content/en/functions/math/ToDegrees.md @@ -0,0 +1,17 @@ +--- +title: math.ToDegrees +description: ToDegrees converts radians into degrees. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.ToDegrees VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.ToDegrees 1.5707963267948966 }} → 90 +``` diff --git a/docs/content/en/functions/math/ToRadians.md b/docs/content/en/functions/math/ToRadians.md new file mode 100644 index 000000000..b5acbb65b --- /dev/null +++ b/docs/content/en/functions/math/ToRadians.md @@ -0,0 +1,17 @@ +--- +title: math.ToRadians +description: ToRadians converts degrees into radians. +categories: [] +keywords: [] +params: + functions_and_methods: + aliases: [] + returnType: float64 + signatures: [math.ToRadians VALUE] +--- + +{{< new-in 0.130.0 />}} + +```go-html-template +{{ math.ToRadians 90 }} → 1.5707963267948966 +``` diff --git a/docs/content/en/functions/math/_index.md b/docs/content/en/functions/math/_index.md new file mode 100644 index 000000000..c58a5a704 --- /dev/null +++ b/docs/content/en/functions/math/_index.md @@ -0,0 +1,6 @@ +--- +title: Math functions +linkTitle: math +description: Use these functions to perform mathematical operations. +categories: [] +--- |