I always thought any power of 1 equals 1, but Math.pow(1, Infinity)
returns NaN. Why not 1?

- 4,247
- 6
- 32
- 43
-
It's the way the Javascript gods wanted it to be – Tina CG Hoehr Sep 01 '12 at 21:59
-
2Not just JavaScript. That's how the math is defined. – Michael Petrotta Sep 01 '12 at 22:00
-
3actually, I expect it's the way the IEEE754 gods defined it to be... – Alnitak Sep 01 '12 at 22:00
-
Yep. Math gods > Javascript gods :P – Tina CG Hoehr Sep 01 '12 at 22:01
-
("Math gods" are theoretical. "IEEE-754 gods" are practical. JavaScript is a practical implementation which *specifically follows IEEE-754* binary64. Although, I am not sure how if `pow` is itself is technically covered by IEEE-754 even if `NaN` is.) – Sep 01 '12 at 22:28
-
1Actually, this behavior of `pow` *is defined* in IEEE-754 2008 (it also defines it in relation to qNaN), however, to find an actually IEEE-754 reference is .. not easy. Also, different programming languages (e.g. C and Java) differ on their implementations/requirements. – Sep 01 '12 at 22:34
4 Answers
This is more of a math question than a Javascript question, and you therefore use mathematical explanations such as the following (http://mathforum.org/library/drmath/view/53372.html):
When you have something like "infinity," you have to realize that it's not a number. Usually what you mean is some kind of limiting process. So if you have "1^infinity" what you really have is some kind of limit: the base isn't really 1, but is getting closer and closer to 1 perhaps while the exponent is getting bigger and bigger, like maybe (x+1)^(1/x) as x->0+.
The question is, which is happening faster, the base getting close to 1 or the exponent getting big? To find out, let's call:
L = lim x->0 of (x+1)^(1/x)
Then:
ln L = lim x->0 of (1/x) ln (x+1) = lim x->0 of ln(x+1) / x
So what's that? As x->0 it's of 0/0 form, so take the derivative of the top and bottom. Then we get lim x->0 of 1/(x+1) / 1, which = 1. So ln L = 1, and L = e. Cool!
Is it really true? Try plugging in a big value of x. Or recognize this limit as a variation of the definition of e. Either way, it's true. The limit is of the 1^infinity form, but in this case it's e, not 1. Try repeating the work with (2/x) in the exponent, or with (1/x^2), or with 1/(sqrt(x)), and see how that changes the answer.
That's why we call it indeterminate - all those different versions of the limit approach 1^infinity, but the final answer could be any number, such as 1, or infinity, or undefined. You need to do more work to determine the answer, so 1^infinity by itself is not determined yet. In other words, 1 is just one of the answers of 1^infinity.
An answer of "indeterminate" is not a number.

- 21,988
- 13
- 81
- 109

- 8,300
- 2
- 31
- 43
-
4You are calculating `lim_{x->1,y->∞}(x^y) = (1)^(∞)`, which is indeterminate. But `lim_{y->∞}(1^y) = 1^(∞) = 1` – Oriol Mar 07 '13 at 19:36
-
1http://math.stackexchange.com/questions/319764/1-to-the-power-of-infinity-why-is-it-indeterminate?rq=1 – Déjà vu Apr 27 '13 at 17:18
Particularly for JS it is defined in the standard, ECMAScript-262 5th Edition, page 163:
If abs(x)==1 and y is +∞, the result is NaN
The reason is that infinity only makes sense with limits.
So
lim 1^x -> ∞
x->∞
but the 1^∞
is undefined (for programming languages. For math it is defined and expressed as a limit)

- 249,484
- 69
- 436
- 539
-
The limit would be written as lim 1^x where x approaches infinity. Your math is bad. Unity to any finite power is certainly well defined and the Cauchy sequence would define the limit as exactly one as expected. – shawnt00 Sep 01 '12 at 22:02
-
@shawnt00: actually I was waiting for this comment :-) I could try to write it in a right way, but I don't know the readable form for correct format. On paper it's easy, but not here – zerkms Sep 01 '12 at 22:02
-
I'm not making a minor point about notation. Your reasoning is simply wrong. – shawnt00 Sep 01 '12 at 22:04
-
-
@shawnt00: well, from math point of view - it is incorrect, but in js you cannot express result as a limit – zerkms Sep 01 '12 at 22:06
-
Well if `1 ^ x = 1` for any `x`, it would follow that it would still hold if `x = ±inf` – lanzz Sep 01 '12 at 22:08
-
-
@lanzz: `If abs(x)==1 and y is +∞, the result is NaN`, page 163 of your link – zerkms Sep 01 '12 at 22:17
The IEEE 754-2008 defines:
1^(+-)Inf = +1
The language you use does not comfort to the standard.

- 588
- 2
- 6
- 24
jeff`s answer is good, but it says:
When you have something like "infinity," you have to realize that it's not a number. Usually what you mean is some kind of limiting process. So if you have "1^infinity" what you really have is some kind of limit: the base isn't really 1, but is getting closer and closer to 1 perhaps while the exponent is getting bigger and bigger, like maybe (x+1)^(1/x) as x->0+.
Well, if you have 1^∞
, of course the exponent can't be exactly ∞
, because it isn't a real number. But the base can be EXACTLY 1 all the time.
Then,
lim (x^y) = (1)^(∞) = ?? undefined ??
x->1
y->∞
But
lim (1^y) = 1^(∞) = 1
y->∞
(The parenthesis notation means that the part inside the parenthesis is a sequence that converges to that number, but it isn't that number)
Then, I think that if Javascript had an integrer type, Math.pow( (int)1, Infinity)
should give 1
.
But the fact is that (https://stackoverflow.com/a/3605946/1529630)
All numbers in JavaScript are 64-bit floating point numbers.
Then, (http://en.wikipedia.org/wiki/Double-precision_floating-point_format), since IEEE 754 double-precision binary floating-point numbers have a significand of 53 bits (52 explicitly stored),
The total precision is therefore 53 bits (approximately 16 decimal digits, 53 log10(2) ≈ 15.955)
So when we do Math.pow(1,Infinity)
, that 1
isn't EXACTLY 1.
Then, it makes sense that Math.pow(1,Infinity)
is NaN
-
2
-
@Bergi I meant that since there are precision errors, a number stored as 1 isn't always the mathematical idea of 1 – Oriol Apr 27 '13 at 17:49