sql
css
python
mysql
linux
xcode
android
eclipse
silverlight
flash
json
algorithm
facebook
oracle
cocoa
tsql
delphi
apache
postgresql
There's nothing wrong with your first example. 0**0 is often defined to be 1.
0**0
The second example is all to do with precision of doubles. 1E900 exceeds the maximum positive value of a (most likely 64-bit) double. If you want doubles outside of that range, you'll have to look into libraries. Fortunately Python has one built-in: the decimal module.
1E900
For example:
from decimal import Decimal d = Decimal('1E900') f = d + d print(f) >>> 2E900
According to Wolfram (quoting Knuth) while 0**0 is indeterminate, it's sometimes given as 1. This is because holding the statement 'x**0 = 1' to be true in all cases is in some cases useful. Even more interestingly Python will consider NaN**0 to be 1 as well.
http://mathworld.wolfram.com/Power.html
In the case of infinity**infinity, you're not really dealing with the mathematical concept of infinity here (where that would be undefined), but rather a number that's too large and has overflowed. As such all that statement is saying is that a number that's huge to the power of another number that's huge is still a number that's huge.
Edit: I do not think it is possible to overload a built in type (such as float) in Python so overloading the float.__pow__(x,y) operator directly. What you could possibly do is define your own version of float.
class myfloat(float): def __pow__(x,y): if(x==y==0): return 'NaN' else: return float.__pow__(x,y) m = myfloat(0) m**0
Not sure if that's exactly what you're looking for though.
Well returning NaN for 0**0 is almost always useless and lots of algorithms avoid special cases if we assume 0**0 == 1. So while it may not be mathematically perfect - we're talking about IEEE-754 here, mathematical exactness is really the least of our problems [1]
0**0 == 1
But if you want to change it, that's rather simple. The following works as expected in Python 3.2:
def my_pow(x, y): if y == 0: return 'NaN' return float.__pow__(float(x), y) pow = my_pow
[1] The following code can theoretically execute the if branch with x86 CPUs (well at least in C and co):
float x = sqrt(y); if (x != sqrt(y)) printf("Surprise, surprise!\n");