Walt Mankowski on Fri, 20 Jun 2003 15:50:52 -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 03:47:42PM -0400, Adam Turoff wrote:
> 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.  :-)

Oh, sorry, I guess that example is a little confusing, isn't it?

The arrays are indexed starting at 0, so it's complaining about the
seconds, not the minutes.

W

Attachment: pgplIukcKW7ga.pgp
Description: PGP signature