-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)
Nicholas Tower
  • 72,740
  • 7
  • 86
  • 98
Avinash Thakur
  • 1,640
  • 7
  • 16
  • 3
    What would you expect the result to be? Anything raised to the power 0 is 1 by mathematical definition. – Pointy May 02 '20 at 16:19
  • Well... [Zero to the power of zero, denoted by 00, is a mathematical expression with no agreed-upon value.](https://en.wikipedia.org/wiki/Zero_to_the_power_of_zero) – Thierry Lathuille May 02 '20 at 16:21
  • @ThierryLathuille sure but that's not what this question is about. – Pointy May 02 '20 at 16:21
  • It's a case of something at the power 0 that isn't so clearly mathematically defined. – Thierry Lathuille May 02 '20 at 16:25
  • Well IEEE 754 math is pretty thoroughly specified. "why" questions like this are not really useful. – Pointy May 02 '20 at 16:25
  • 1
    I think that referring to IEEE 754 is the right answer, though. It says in 6.1 - infinity arithmetics: 'The behavior of infinity in floating-point arithmetic is derived from the limiting cases of real arithmetic with operands of arbitrarily large magnitude, when such a limit exists.' So, of course, 1 makes total sense. – Thierry Lathuille May 02 '20 at 16:33
  • Don't confuse being an indeterminate form with being undefined. They're not the same thing. It's perfectly fine to define infinity**0 to be 1 while still describing it as an indeterminate form in the context of evaluating limits. – Mark Dickinson May 02 '20 at 17:35
  • @ThierryLathuille: Note that IEEE 754 hedges its bets on this topic, though. It defines various power operations, including one called `powr` for which `powr(+∞, ±0)` signals the invalid operation exception. (See section 9.2.1 of the 2019 IEEE 754 revision.) – Mark Dickinson May 02 '20 at 17:43

1 Answers1

1

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)

Community
  • 1
  • 1
Nicholas Tower
  • 72,740
  • 7
  • 86
  • 98