mardi 17 mai 2016

Why the following works in ruby?

to_a over a range of integers behaves differently in this case. Upto 15 decimals, include? returns false but once it reached 16 decimals array considers the decimal digit as part of array.

Why?

2.2.1 :020 > (1..9).to_a.include?(8.999999999999999)
 => false 
2.2.1 :021 > (1..9).to_a.include?(8.9999999999999999)
 => true 
2.2.1 :022 >

And why range only says this is true

2.2.1 :001 > (1..9).include?(8.9)
 => true 

Aucun commentaire:

Enregistrer un commentaire