On Tue, 31 Jul 2007, Paul Cochrane wrote:

> Hi all,
> 
> I'm wanting to remove all the floating point comparison warnings which
> appear when compiling parrot and wanted some advice as to how best to
> achieve this.
> 
> Floating point comparisons appear in code such as (taken from src/string.c):
> 
>     if (*p == '-' && f == 0.0)
> 
> I'd like to replace this with
> 
>     if (*p == '-' && is_float_equal(f, 0.0))
> 
> where
> 
> #define EPSILON 0.0000005
> 
> INTVAL is_float_equal(FLOATVAL x, FLOATVAL y)
> {
>     return (fabs(x - y) <= fabs(x + y)*EPSILON) ? 1 : 0;
> }

I don't think you want to do that.  This particular case is testing 
specifically for exactly -0.0.  It's that one pathological case that's 
being tested for.

Now there may be other spots in parrot where floating point comparisons 
are being made for other reasons.  For those, you may indeed want to ask 
how precise the comparison ought to be, but I expect those are quite rare.

-- 
    Andy Dougherty              [EMAIL PROTECTED]

Reply via email to