Fun with complex and IEEE

Nick Maclaren nmm1 at cus.cam.ac.uk
Thu Jun 15 13:34:59 EDT 2006


Try this one for size, noting especially the delightful eccentric value
at i = 8.  Your results may vary.

m = 1.0e308
for i in range(0,20) :
    c = (1.0e308+1.0e308j)/(1.0e308+i*0.1*1.0e308j)
    print i, c

On at least two systems, it gives:

0 (1+1j)
1 (1.08910891089+0.891089108911j)
2 (1.15384615385+0.769230769231j)
3 (1.19266055046+0.642201834862j)
4 (1.20689655172+0.51724137931j)
5 (1.2+0.4j)
6 (1.17647058824+0.294117647059j)
7 (1.14093959732+0.201342281879j)
8 (inf+0.121951219512j)
9 (nan+0j)
10 (nan+0j)
11 (nan-0j)
12 (nan-0j)
13 -0j
14 -0j
15 -0j
16 -0j
17 -0j
18 -0j
19 -0j

Regards,
Nick Maclaren.



More information about the Python-list mailing list