"Standard is better than better." -Anon.

Also, you don't need a "to_f" to reproduce this -- just enter "0.5 -
0.4 - 0.1" into any Ruby, Python or JavaScript interpreter -- or a C
or Java program, for that matter -- to get a perfectly consistent, and
consistently surprising, very very small negative number that is not
*quite* zero.

So how to test around this in unit tests? In RSpec, use be_within (n=E9e
be_close) [1]; in Wrong (which works inside many test frameworks), use
close_to? [2]

 - A

[1]
https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/t=
emperature/temperature_spec.rb
[2] https://github.com/sconover/wrong/blob/master/lib/wrong/close_to.rb

--
Alex Chaffee - alex / stinky.com
http://alexchaffee.com
http://twitter.com/alexch