Why is the value of 1**Inf equal to 1, not NaN?

239 views Asked by At

Why is 1**Inf == 1 ?

I believe it should be NaN, just like Inf-Inf or Inf/Inf.

How is exponentiation implemented on floats in python? exp(y*log(x)) would get correct result :/

3

There are 3 answers

0
Yu Hao On BEST ANSWER

You are right, mathematically, the value of 1∞ is indeterminate.

However, Python doesn't follow the maths exactly in this case. The document of math.pow says:

math.pow(x, y)

Return x raised to the power y. Exceptional cases follow Annex ‘F’ of the C99 standard as far as possible. In particular, pow(1.0, x) and pow(x, 0.0) always return 1.0, even when x is a zero or a NaN.

2
Bruce On

Technically 1^inf is defined as limit(1^x, x->inf). 1^x = 1 for any x >1, so it should be limit(1,x->inf) = 1, not NaN

0
Stephen Canon On

Floating-point arithmetic is not real-number arithmetic. Notions of "correct" informed by real analysis do not necessarily apply to floating-point.

In this case, however, the trouble is just that pow fundamentally represents two similar but distinct functions:

  • Exponentiation with an integer power, which is naturally a function RxZ --> R (or RxN --> R).
  • The two-variable complex function given by pow(x,y) = exp(y * log(x)) restricted to the real line.

These functions agree for normal values, but differ in their edge cases at zero, infinity, and along the negative real axis (which is traditionally the branch cut for the second function).

These two functions are sometimes divided up to make the edge cases more reasonable; when that's done the first function is called pown and the second is called powr; as you have noticed pow is a conflation of the two functions, and uses the edge cases for these values that come from pown.