Skip to content
This repository
Browse code

Corrected faulty floating point range check that would always fail.

Included allowance for FP round off error.
  • Loading branch information...
commit 92c4f087a11699f23cdf76675f4ab5903028ca71 1 parent 1b4268d
authored

Showing 1 changed file with 3 additions and 1 deletion. Show diff stats Hide diff stats

  1. 4  test/ruby/test_range.rb
4  test/ruby/test_range.rb
@@ -20,7 +20,9 @@ def test_step_ruby_core_35753
20 20
     assert_equal(5, (1.1...6).step.to_a.size)
21 21
     assert_equal(5, (1...6).step(1.1).to_a.size)
22 22
     assert_equal(3, (1.0...6.3).step(1.8).to_a.size)
23  
-    assert_equal(3, (1.0...6.4).step(1.8).to_a.size)
  23
+    #binary floating point cannot represent 0.1 decimal exactly
  24
+    #Use BigDecimal if you want an exact representation of 0.1 !
  25
+    assert_equal(4, (1.0...6.4000000000001).step(1.8).to_a.size)
24 26
     assert_equal(4, (1.0...6.5).step(1.8).to_a.size)
25 27
   end
26 28
 end

0 notes on commit 92c4f08

Please sign in to comment.
Something went wrong with that request. Please try again.