Weirdness

Bradley Dean bjdean at bjdean.id.au
Mon Feb 25 17:31:34 GMT 2008


On Mon, Feb 25, 2008 at 06:21:13PM +0100, Rafael Garcia-Suarez wrote:
> On 25/02/2008, Dan Rowles <d.rowles at outcometechnologies.com> wrote:
> >  Now, I know very little about machine representations of floating point
> >  numbers, but I *guess* that this means that the numbers differ by too
> >  small an amount to print out, even though they do differ.
> >
> >  So my question to you is, should I report this as a bug somewhere, or
> >  should I just ignore it as "floating point weirdness"?
> 
> perl's printf (and Devel::Peek) don't print every available digit for
> floating point numbers, but use a default precision of whatever your
> platform defines the C macro DBL_DIG to be (that's often 6 on the
> average Linux system. In your case, that's 6 indeed)
> 
> If you want more decimals, you need to tell perl to do so, eg. with a
> format "%.10f".
> 
> I guess that could be documented more accurately...
> 

You could change the test to check whether the floats are similiar enough
(ie one minus the other is sufficient close to zero) - probably a safer
approach when dealing with floats.

Cheerio,

 Brad

-- 
Bradley Dean
Software Engineer - http://bjdean.id.au/
Email: bjdean at bjdean.id.au Skype: skype at bjdean.id.au
Mobile(Aus): +61-413014395 Mobile(UK): +44-7846895073


More information about the london.pm mailing list