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

John Machin sjmachin at lexicon.net
Thu Oct 23 05:33:30 EDT 2008


On Oct 23, 8:21 pm, Tzury Bar Yochay <Afro.Syst... at gmail.com> wrote:
> What is the reason math.pow yields OverflowError while python itself
> can
> calculate these large numbers. e.g:
>
> >>> import math
> >>> math.pow(100, 154)
> 1e+308
> >>> math.pow(100, 155)
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> OverflowError: math range error>>> eval(('100*'* 155)[:-1])
>
> 10000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000000
> 0000000000000000L

Because math.pow returns a float; 100 ** 155 won't fit in a float.



More information about the Python-list mailing list