bug-gnulib
[Top][All Lists]
Advanced

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

Re: support for bitwise comparison of floats


From: Paul Eggert
Subject: Re: support for bitwise comparison of floats
Date: Thu, 29 Mar 2007 16:34:41 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

The "right" way to test for -0 versus +0 is to use copysign.
For example, instead of this:

        if (arg < 0.0L)
          {
            sign = -1;
            arg = -arg;
          }
        else if (arg == 0.0L)
          {
            /* Distinguish 0.0L and -0.0L.  */
            static long double plus_zero = 0.0L;
            long double arg_mem = arg;
            if (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0)
              {
                sign = -1;
                arg = -arg;
              }
          }


vasnprintf.c should do this:

        if (copysignl (1, arg) < 0)
          {
            sign = -1;
            arg = -arg;
          }

This is a valid transformation since we know at this point that ARG is
not a NaN.

I think it's much cleaner.  And the code is smaller on my platform,
anyway: no function call is generated for copysignl.  It should be
fast enough for vasnprintf.

This needs copysignl for older platforms, but another gnulib module
should suffice for that....




reply via email to

[Prev in Thread] Current Thread [Next in Thread]