#39292·terraform

log and pow return positive/negative infinity as valid numbers instead of errors

Author: Sanjays2402Created Sep 25, 2026Updated Sep 28, 2026
Labelsbugnew

log() and pow() accept inputs whose true mathematical result is infinite and return them as ordinary cty.Number values with no diagnostic:

log(0, 10)    => -Inf
log(10, 1)    => +Inf
pow(10, 1000) => +Inf
pow(0, -1)    => +Inf

Terraform numbers are assumed finite everywhere downstream, so the error surfaces far from the originating call:

  • jsonencode(pow(10, 1000)) fails with cannot serialize infinity as JSON
  • tostring(pow(10, 1000)) yields the nonstandard string "+Inf"
  • terraform console prints +Inf
  • arithmetic silently propagates it (sum([+Inf]) is +Inf), until sum([+Inf, -Inf]) errors with can't compute sum of opposing infinities

The sibling NaN case was fixed in #38912 by rejecting math.IsNaN(result) with result is not a number, but the infinity case was missed. In internal/lang/funcs/number.go, both LogFunc and PowFunc check only math.IsNaN(result) before returning cty.NumberFloatVal(result); there is no math.IsInf check.

Expected: like NaN, an infinite result should be rejected at the originating call, mirroring #38912.

Seen on main at 55d258b (2026-09-25), version 1.18.0-dev.