On 3 May 2009, at 20:07, Bill Ward wrote:
For my module Number::Format I am getting a strange result from cpan
testers that I can't replicate. See this error report...
http://www.nntp.perl.org/group/perl.cpan.testers/2009/03/msg3560533.html
# Failed test 'pi with precision=6'
# at t/round.t line 18.
# got: 3.141593
# expected: 3.141593
# Failed test 'precision=-2'
# at t/round.t line 24.
# got: 123500
# expected: 123500
# Looks like you failed 2 tests of 16.
t/round.t ............
Here are the test cases in question:
cmp_ok(round(PI,6), '==', 3.141593, 'pi with
precision=6');
cmp_ok(round(123456.78951, -2), '==', 123500, 'precision=-2' );
Since it's using '==' it shouldn't be possible to get those errors,
right? Anyone have any thoughts?
Yeah, that's floating point. There can be a difference between the two
values that's too small to display but big enough to make them non-
equal. '==' is /always/ risky with FP values.
You should instead check for the value being within an acceptable range.
--
Andy Armstrong, Hexten