0

I just discovered a bug, and, even though it is of minor importance, I would like to know if anyone knew why it arises.

bin_width=0.005
max_value=0.7
min_value=0.
bins_=[]
num_step=int((max_value-min_value)/bin_width)
for i in range(0,num_step):
    print i,i*bin_width
    bins_=bins_+[i*bin_width]
print bins_

In this code, the value i*bin_width sometimes differs from the one introduce in the array. For example, bins_[41]=0.20500000000000002, whereas 41*0.005=0.205.

Is that a known bug, and why does it occur ?

Thank you

Martin F
  • 47
  • 1
  • 9
  • Fun experiment: enter `41*0.005` into the REPL and it will output `0.20500000000000002`. Enter `print 41*0.005` and it will output `0.205`. – Kevin Mar 28 '16 at 18:19
  • Sorry for the duplicate, learned a lot thank you. – Martin F Mar 28 '16 at 18:27

0 Answers0