On 7/31/07, Paul Cochrane <[EMAIL PROTECTED]> 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;
> }
That may not be a bad idea, but I think there's a bug in that code --
take, for example, the case where x and y both equal approximately a
million (or more).
Maybe you wanted this instead:
return (fabs(x - y) <= EPSILON) ? 1 : 0;
> (this code was adapted from equivalent fortran code given here:
> http://www.lahey.com/float.htm courtesy of particle++).
>
> Is this a good way to achieve the goal of safe floating point
> comparisons? The #define and function need to go somewhere. Where
> exactly? And which header gets the declaration? parrot.h? Is there
> a better way to do this? Could/should I be using a macro instead?
>
> Thanks heaps in advance!
>
> Paul
>