Skip to content

Commit

Permalink
Corrected faulty floating point range check that would always fail.
Browse files Browse the repository at this point in the history
Included allowance for FP round off error.
  • Loading branch information
brentr authored and FooBarWidget committed Dec 30, 2011
1 parent 538290f commit c8f7ec9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/ruby/test_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def test_step_ruby_core_35753
assert_equal(5, (1.1...6).step.to_a.size)
assert_equal(5, (1...6).step(1.1).to_a.size)
assert_equal(3, (1.0...6.3).step(1.8).to_a.size)
assert_equal(3, (1.0...6.4).step(1.8).to_a.size)
#binary floating point cannot represent 0.1 decimal exactly
#Use BigDecimal if you want an exact representation of 0.1 !
assert_equal(4, (1.0...6.4000000000001).step(1.8).to_a.size)
assert_equal(4, (1.0...6.5).step(1.8).to_a.size)
end
end

0 comments on commit c8f7ec9

Please sign in to comment.