Search code examples
javascriptpythonmathinfinity

Why infinity to power 0 is implemented to be 1?


This is an undeterminate form in Math, but in Python and JavaScript it results in 1. Tested in

Python:

inf=float('inf')
print(inf**0)

JavaScript

console.log(Math.pow(Infinity,0))
console.log(Infinity**0)


Solution

  • That's just the way the specification is defined:

    6.1.6.1.3 Number::exponentiate ( base, exponent )

    Returns an implementation-dependent approximation of the result of raising base to the power exponent.

    If exponent is NaN, the result is NaN.
    If exponent is +0, the result is 1, even if base is NaN.
    [...]

    Source: https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate (emphasis by answerer)