tags:

views:

328

answers:

2

Is there in Ruby some functionality/syntax to compare two floats with delta? Something similar to *assert_in_delta(expected_float, actual_float, delta)* from test/unit but returning Boolean?

+5  A: 
(expected_float - actual_float).abs <= delta
ysth
That's pretty much what assert_in_delta checks, aside from some extra assertions to make sure the arguments can be converted to floats and that delta is not negative.
Firas Assaad
A: 

you may also need a relative tolerance / delta calculation

http://realtimecollisiondetection.net/blog/?p=89

Gene T