Skip to content

Instantly share code, notes, and snippets.

@stefl
Created October 14, 2010 07:19
Show Gist options
  • Save stefl/625762 to your computer and use it in GitHub Desktop.
Save stefl/625762 to your computer and use it in GitHub Desktop.
If you do this:
(205.00).floor
You would expect 205.
Likewise with:
(2.05*100).floor
What you actually get is 204.
Let's see which other values this is true for.
x = 0
while x < 1000 do
x += 0.01
expected = (x*100.00).to_s.to_i
actual = (x*100.00).floor
unless ( actual == expected )
puts "WTF!: Expected #{expected}, but got #{actual}"
end
end
On ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] I get:
WTF!: Expected 11, but got 10
WTF!: Expected 12, but got 11
WTF!: Expected 13, but got 12
WTF!: Expected 14, but got 13
WTF!: Expected 207, but got 206
WTF!: Expected 208, but got 207
WTF!: Expected 209, but got 208
WTF!: Expected 210, but got 209
WTF!: Expected 211, but got 210
WTF!: Expected 212, but got 211
WTF!: Expected 213, but got 212
WTF!: Expected 214, but got 213
WTF!: Expected 215, but got 214
WTF!: Expected 216, but got 215
WTF!: Expected 217, but got 216
WTF!: Expected 218, but got 217
WTF!: Expected 219, but got 218
WTF!: Expected 220, but got 219
WTF!: Expected 221, but got 220
WTF!: Expected 222, but got 221
WTF!: Expected 223, but got 222
WTF!: Expected 224, but got 223
WTF!: Expected 225, but got 224
WTF!: Expected 226, but got 225
WTF!: Expected 227, but got 226
WTF!: Expected 228, but got 227
WTF!: Expected 229, but got 228
WTF!: Expected 1760, but got 1759
WTF!: Expected 1761, but got 1760
WTF!: Expected 1762, but got 1761
WTF!: Expected 1763, but got 1762
WTF!: Expected 1764, but got 1763
WTF!: Expected 1765, but got 1764
WTF!: Expected 1766, but got 1765
WTF!: Expected 1767, but got 1766
WTF!: Expected 1768, but got 1767
WTF!: Expected 1769, but got 1768
WTF!: Expected 1770, but got 1769
WTF!: Expected 1771, but got 1770
WTF!: Expected 1772, but got 1771
WTF!: Expected 1773, but got 1772
WTF!: Expected 1774, but got 1773
WTF!: Expected 1775, but got 1774
WTF!: Expected 1776, but got 1775
WTF!: Expected 1777, but got 1776
WTF!: Expected 1778, but got 1777
WTF!: Expected 1779, but got 1778
WTF!: Expected 1780, but got 1779
WTF!: Expected 1781, but got 1780
WTF!: Expected 1782, but got 1781
WTF!: Expected 1783, but got 1782
WTF!: Expected 1784, but got 1783
WTF!: Expected 1785, but got 1784
WTF!: Expected 1786, but got 1785
WTF!: Expected 1787, but got 1786
WTF!: Expected 1788, but got 1787
WTF!: Expected 1789, but got 1788
WTF!: Expected 1790, but got 1789
WTF!: Expected 4310, but got 4309
WTF!: Expected 4311, but got 4310
WTF!: Expected 4312, but got 4311
WTF!: Expected 4313, but got 4312
WTF!: Expected 4314, but got 4313
WTF!: Expected 4315, but got 4314
WTF!: Expected 4316, but got 4315
WTF!: Expected 4317, but got 4316
WTF!: Expected 4318, but got 4317
WTF!: Expected 4319, but got 4318
WTF!: Expected 4320, but got 4319
WTF!: Expected 4321, but got 4320
WTF!: Expected 4322, but got 4321
WTF!: Expected 4323, but got 4322
WTF!: Expected 4324, but got 4323
WTF!: Expected 4325, but got 4324
WTF!: Expected 4326, but got 4325
WTF!: Expected 4327, but got 4326
WTF!: Expected 4328, but got 4327
WTF!: Expected 4329, but got 4328
WTF!: Expected 4330, but got 4329
WTF!: Expected 4331, but got 4330
WTF!: Expected 4332, but got 4331
WTF!: Expected 7205, but got 7204
WTF!: Expected 7206, but got 7205
WTF!: Expected 7207, but got 7206
WTF!: Expected 7208, but got 7207
WTF!: Expected 7209, but got 7208
WTF!: Expected 7210, but got 7209
WTF!: Expected 7211, but got 7210
WTF!: Expected 7212, but got 7211
WTF!: Expected 15942, but got 15941
WTF!: Expected 15943, but got 15942
WTF!: Expected 15944, but got 15943
WTF!: Expected 15945, but got 15944
WTF!: Expected 15946, but got 15945
WTF!: Expected 15947, but got 15946
WTF!: Expected 15948, but got 15947
WTF!: Expected 15949, but got 15948
WTF!: Expected 15950, but got 15949
WTF!: Expected 15951, but got 15950
WTF!: Expected 15952, but got 15951
WTF!: Expected 15953, but got 15952
WTF!: Expected 15954, but got 15953
WTF!: Expected 15955, but got 15954
WTF!: Expected 15956, but got 15955
WTF!: Expected 15957, but got 15956
WTF!: Expected 15958, but got 15957
WTF!: Expected 15959, but got 15958
WTF!: Expected 15960, but got 15959
WTF!: Expected 15961, but got 15960
WTF!: Expected 15962, but got 15961
WTF!: Expected 15963, but got 15962
WTF!: Expected 15964, but got 15963
WTF!: Expected 15965, but got 15964
WTF!: Expected 15966, but got 15965
WTF!: Expected 15967, but got 15966
WTF!: Expected 15968, but got 15967
WTF!: Expected 15969, but got 15968
WTF!: Expected 15970, but got 15969
WTF!: Expected 15971, but got 15970
WTF!: Expected 15972, but got 15971
WTF!: Expected 15973, but got 15972
WTF!: Expected 15974, but got 15973
WTF!: Expected 15975, but got 15974
WTF!: Expected 15976, but got 15975
WTF!: Expected 15977, but got 15976
WTF!: Expected 15978, but got 15977
WTF!: Expected 15979, but got 15978
WTF!: Expected 15980, but got 15979
WTF!: Expected 15981, but got 15980
WTF!: Expected 15982, but got 15981
WTF!: Expected 15983, but got 15982
WTF!: Expected 15984, but got 15983
WTF!: Expected 15985, but got 15984
WTF!: Expected 15986, but got 15985
WTF!: Expected 15987, but got 15986
WTF!: Expected 15988, but got 15987
WTF!: Expected 15989, but got 15988
WTF!: Expected 15990, but got 15989
WTF!: Expected 15991, but got 15990
WTF!: Expected 15992, but got 15991
WTF!: Expected 15993, but got 15992
WTF!: Expected 15994, but got 15993
WTF!: Expected 15995, but got 15994
@bensummers
Copy link

Interestingly, JRuby does this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment