Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

srange bug?

Lets say that we want a list of the numbers 0,0.001,0.002 ... 2 if we use srange after some values we have rounding errors:

srange(0,2,0.001)
... 1.13799999999999, 1.13899999999999, 1.13999999999999, 1.14099999999999, 1.14199999999999...

why? Is this a bug? A quick solution is to use numpy:

import numpy as np
p=np.arange(0,2,0.001);p

array([  0.00000000e+00,   1.00000000e-03,   2.00000000e-03, ...,
         1.99700000e+00,   1.99800000e+00,   1.99900000e+00])

but the question remains... why srange doesn't work correctly?

(tested on Sage 5.0.1 & 5.0 & 4.7.2)