I get this from <code>print math.pow(2,64)</code>:
I want this:
I'm lazy... I don't want to convert it manually :)
Explicitly converting it to `int` works for me. (Without the 3-digit-
block notation, of course.)
> Explicitly converting it to `int` works for me. (Without the 3-digit-
> block notation, of course.)
Ah yes, that works too... thanks. I've settled on doing it this way:
I like the added parenthesis :)
I was surprised to find that gives an exact (integer, not
floating-point) answer. Still, I think it's better to say 2**64
which also works for (e.g.) 2**10000 where math.pow(2,10000)
raises an exception.
>>> x = 1.84467440737e+19
>>> print '%25.3f' % x
>>> print '%12.5e' % x
>>> print '%12.5g' % x
See http://docs.python.org/lib/typesseq-strings.html for all he details.
It *is* binary floating point. Powers of 2 are exactly
representable. Of course, it doesn't give an exact answer in general.
>>> int(math.pow(10, 23))
Oh yikes, good point. math.pow(2,64) is really not appropriate for
what the OP wanted, I'd say. If you want integer exponentiation, then
write it that way. Don't do a floating point exponentiation that just
happens to not lose precision for the specific example.
>>> int(math.pow(3,50)) # wrong
>>> 3**50 # right