Adam Turoff on Fri, 20 Jun 2003 15:47:53 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Floating point roundoff in cpan test scripts


On Fri, Jun 20, 2003 at 11:38:03AM -0400, Walt Mankowski wrote:
> I just put up my first module on CPAN the other day[1], and this
> morning I got an email from cpan-testers saying that it some of the
> tests failed on Solaris.
> 
> I'm using Test::More to do the tests.  The line that fails is
> 
>   is_deeply( [decimal2dms(  0.25416666666666667 )], [ 0, 15, 15]);
> 
> The error it's returning is
> 
> #     Structures begin differing at:
> #          $got->[2] = '15.0000000000001'
> #     $expected->[2] = '15'
> 
> Is there any easy way I can tell it that if it's within a given delta
> of the value I'm looking for, it's close enough?

Um, it looks like you're trying to convert a decimal to degrees, minutes
and seconds.  By definition, if you're going d/m/s, the first two values
should be integers.  There's no point in having a fractional minute and
also calculating seconds...

Pass the first two results through int() and see if that helps.  :-)

Z.

-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**