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 :/
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 :/
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:
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
.
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: