ilogbl(0.0L) value is wrong

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Dec 16 10:21:00 GMT 2019


Hi Bruno,

On Dec 12 11:26, Bruno Haible wrote:
> POSIX [1] specifies that the return value of the functions ilogbf(), ilogb(),
> ilogbl() for a zero argument should all be the same, namely FP_ILOGB0.
> 
> [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/ilogb.html
> 
> In Cygwin 2.9, the value of ilogbl(0.0L) is not right.
> 
> How to reproduce:
> ============================== foo.c ==============================
> #include <stdio.h>
> #include <float.h>
> #include <math.h>
> 
> int main ()
> {
>   int x = ilogbf (0.0f);
>   int y = ilogb (0.0);
>   int z = ilogbl (0.0L);
>   printf ("%d\n%d\n%d\n%d\n", x, y, z, FP_ILOGB0);
> }
> ===================================================================
> $ gcc -Wall foo.c
> $ ./a.exe
> 
> Expected output: four times the same number.
> Actual output:
> 
> -2147483647
> -2147483647
> -2147483648
> -2147483647

Oh well.  Again, this is upstream code, this time taken almost verbatim
from

  https://sourceforge.net/projects/mingw-w64/

I don't see any upstream patch indicating that ilogbl has been changed,
but checking the glibc source I found that the x86{_64} assembler code
apparently needs another check to allow returning FP_ILOGB0 in this
scenario.

However, it looks like this is a Cygwin/newlib problem only, given that
FP_ILOGB0 is defined as 0x80000000 in Mingw-w64, but (for historical
reasons I assume) as 0x80000001 in newlib.  The Mingw-w64 code already
returns 0x80000000 without this extra check.  Weird that glibc needs
it, though...

I pushed this patch:

  https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=29ba52da9553

Please test the latest developer snapshot from https://cygwin.com/snapshots/

I'll hold back the 3.1.0 release for a day or two.  Maybe we can fix
the strtold problem as well.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20191216/ed7b55e8/attachment.sig>


More information about the Cygwin mailing list