[Mesa-dev] [PATCH 1/2] mesa: add signbit() macro

Brian Paul brianp at vmware.com
Mon Sep 24 14:09:56 PDT 2012


On 09/24/2012 02:53 PM, Jose Fonseca wrote:
>> From signbit manpage:
>
>    This is not the same as x<  0.0, because IEEE 754 floating point allows zero to be signed.   The  comparison  -0.0<   0.0  is    false, but signbit(-0.0) will return a nonzero value.
>
> I think that for consistency (and especially because MSVC ends not being as widely tested as gcc), we should match the spec. This can easily be done using an inline and an union.

The DIFFERENT_SIGNS and IS_NEGATIVE macro are only used in the tnl 
clipping code and I don't think the signbit() of 0 vs -0 would make 
any real difference in the end.

But I see your point.  Who knows where signbit might be used in the 
future and consistency is good.  The question then is how closely do 
we want to follow Linux's example?  The code in math.h checks 
sizeof(x) to handle float and double (and long double) specially:

/* Return nonzero value if sign of X is negative.  */
# ifdef __NO_LONG_DOUBLE_MATH
#  define signbit(x) \
      (sizeof (x) == sizeof (float) ? __signbitf (x) : __signbit (x))
# else
#  define signbit(x) \
      (sizeof (x) == sizeof (float)					      \
       ? __signbitf (x)							      \
       : sizeof (x) == sizeof (double)					      \
       ? __signbit (x) : __signbitl (x))
# endif


-Brian


More information about the mesa-dev mailing list