H
Henry Jones
Hi,
I was writing some unit tests when I ran into some troubles.. In the end
I found out the problem :
BigDecimal.new('15.25') == 15.25
returns false !!
BigDecimal.new('15.25').to_f == 15.25.to_f also returns false.
Substracting both values returns 1.7763... e-015
This is on ruby 1.8.6, Win32.
I'm a comp. engineer, so I know it's ultimately related to the binary
value of 15.25 which cannot be precisely represented (without an
infinite number of bits) , but I'm still amazed that such a simple
comparison with a literal value should fail...
I was writing some unit tests when I ran into some troubles.. In the end
I found out the problem :
BigDecimal.new('15.25') == 15.25
returns false !!
BigDecimal.new('15.25').to_f == 15.25.to_f also returns false.
Substracting both values returns 1.7763... e-015
This is on ruby 1.8.6, Win32.
I'm a comp. engineer, so I know it's ultimately related to the binary
value of 15.25 which cannot be precisely represented (without an
infinite number of bits) , but I'm still amazed that such a simple
comparison with a literal value should fail...