Skip Menu |

This queue is for tickets about the Algorithm-LineSegments CPAN distribution.

Report information
The Basics
Id: 94055
Status: resolved
Priority: 0/
Queue: Algorithm-LineSegments

People
Owner: BJOERN [...] cpan.org
Requestors: DANAJ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 0.04



Subject: Floating point in tests
In version 0.03, with a long double enabled Perl, I get: t/02simple.t .. 1/1 # Failed test 'reftest' # at t/02simple.t line 116. # Structures begin differing at: # $got->[0][0][1] = '9.4639403869223315e-08' # $expected->[0][0][1] = '9.46394038692233e-08' # Looks like you failed 1 test of 1. t/02simple.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/1 subtests I think you may need to use something like Test::Number::Delta or do something similar by hand. Floating point is just not portable in any exact sense.
The release was intended to address that, but I see my simple approach was insufficient (the module only copies the NVs into the output, the output is not from floating point calculations, so these are just serialisation differences). I have now used Test::Deep for it. Thank you.
On Fri Mar 21 14:15:42 2014, BJOERN wrote: Show quoted text
> The release was intended to address that, but I see my simple approach > was insufficient (the module only copies the NVs into the output, the > output is not from floating point calculations, so these are just > serialisation differences). I have now used Test::Deep for it. Thank > you.
(see issue at the end of this -- it's not serialization, it is that you have assumed NV to be a IEEE 754 double and truncate for you). The good news is that the test passes with long double Perl. The bad news is that with a tolerance of 1 it is ignoring the values. I think you could use something like: my $tol = 1e-15; ... num(9.46394038692233e-008, $tol) ... num(3.66040410426649e-007, $tol) ... etc. That way you do test that you're getting the right numbers, but only using the first part. As it is now, it will accept any of your points as matching (because they're all within 1 of each other). I also would recommend using the same values in the comparison. That is, you enter: 9.4639403869223315e-08 as the first point, but then compare vs. 9.46394038692233e-008 which are *different* numbers. They are equal with IEEE 754 doubles, but not when NVs are something else. I think this is the root of the problem, not "serialization".