[Tutor] largest and smallest numbers

Dick Moores rdm at rcblue.com
Mon Oct 15 08:15:30 CEST 2007


At 06:01 PM 9/24/2007, Terry Carroll wrote:
>On Mon, 24 Sep 2007, Christopher Spears wrote:
>
> > How can I find the largest float and complex numbers?
>
>That's an interesting question..
>
>I just tried this:
>
>x = 2.0
>while True:
>     x = x*2
>     print x
>     if repr(x) == "1.#INF": break
>
>to just keep doubling X until Python began representing it as infinity.
>My output:
>
>4.0
>8.0
>16.0
>32.0
>64.0
>128.0
>  . . .
>137438953472.0
>274877906944.0
>549755813888.0
>1.09951162778e+012
>2.19902325555e+012
>4.3980465111e+012
>  . . .
>2.24711641858e+307
>4.49423283716e+307
>8.98846567431e+307
>1.#INF
>
>So I'd say, the answer is somewhere between 8.98846567431e+307 and double
>that.

I pinched it down some more (after dinner):

 >>> 1.79769313486e+308 * (1.000000000000001 ** 1160)
1.7976931348623151e+308
 >>> 1.79769313486e+308 * (1.000000000000001 ** 1161)
1.#INF

Dick Moores
Win XP




More information about the Tutor mailing list