Skip to navigation

Numeric functions

Numeric functions accept finite numbers. Integer-only operations retain signed 64-bit precision; fractional literals and calculations use finite IEEE 754 double precision.

FunctionResult and rules
abs(number)Absolute value; integer overflow fails.
ceil(number)Round upward to an integral value.
floor(number)Round downward to an integral value.
log(number, base)Logarithm; an invalid domain or nonfinite result fails.
max(numbers...)Largest of one or more numbers.
min(numbers...)Smallest of one or more numbers.
parseint(text, base)Parse a signed integer in base 2–62. Bases through 36 ignore letter case; above 36 use a–z then A–Z.
pow(base, exponent)Raise a number to a power; nonfinite results fail.
signum(number)Return -1, 0, or 1.

Integer abs, ceil, floor, parseint, and integer-only min/max preserve precision. Resource integer fields and external number inputs reject fractions. Fractional variable defaults are also rejected. Use arithmetic operators for ordinary calculations; they follow the same integer and fraction rules.

Example

locals {
numbers = {
absolute = abs(-7)
ceiling = ceil(1.2)
floor = floor(1.8)
logarithm = log(8, 2)
largest = max([1, 2, 3]...)
smallest = min(1, 2, 3)
parsed = parseint("ff", 16)
powered = pow(2, 3)
sign = signum(-2)
}
}
output "numbers" {
type = string
value = jsonencode(local.numbers)
}

All calls obey the function limits and annotation rules.