why does math.pow yields OverflowError (while python itself can calculate that large number)

Christian Heimes lists at cheimes.de
Thu Oct 23 06:42:49 EDT 2008


Tzury Bar Yochay wrote:
>> Because math.pow returns a float; 100 ** 155 won't fit in a float.
> 
> Sure that is the reason.
> May I rephrase, my question:
> Why not returning another type as long as we can calculate it?
> After all, math module is likely to be used on large numbers as well.

Because it's very complicated to get it right. The math module is a thin 
wrapper around the platform math library. It took Mark and me very long 
to get cmath and math right for floats (C doubles). Arbitrary precision 
and arbitrary length numbers are a different story. You have to use 3rd 
party tools for those. The standard library aims to solve common 
problems, not special problems.

Christian




More information about the Python-list mailing list