public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* ilogbl(0.0L) value is wrong
@ 2019-12-12 12:00 Bruno Haible
  2019-12-16 10:21 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2019-12-12 12:00 UTC (permalink / raw)
  To: cygwin

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


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ilogbl(0.0L) value is wrong
  2019-12-12 12:00 ilogbl(0.0L) value is wrong Bruno Haible
@ 2019-12-16 10:21 ` Corinna Vinschen
  2019-12-17 14:04   ` Bruno Haible
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2019-12-16 10:21 UTC (permalink / raw)
  To: Bruno Haible; +Cc: cygwin

[-- Attachment #1: Type: text/plain, Size: 1926 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ilogbl(0.0L) value is wrong
  2019-12-16 10:21 ` Corinna Vinschen
@ 2019-12-17 14:04   ` Bruno Haible
  2019-12-17 15:41     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2019-12-17 14:04 UTC (permalink / raw)
  To: cygwin, Corinna Vinschen; +Cc: Corinna Vinschen

[-- Attachment #1: Type: text/plain, Size: 312 bytes --]

Hi Corinna,

> 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 can't test it easily.

But the code looks good; only the comments could be improved; patch attached.

Bruno

[-- Attachment #2: ilogbl-comment.diff --]
[-- Type: text/x-patch, Size: 1011 bytes --]

diff --git a/winsup/cygwin/math/ilogbl.S b/winsup/cygwin/math/ilogbl.S
index a4fe503..e4a2660 100644
--- a/winsup/cygwin/math/ilogbl.S
+++ b/winsup/cygwin/math/ilogbl.S
@@ -17,14 +17,14 @@
 __MINGW_USYMBOL(ilogbl):
 #ifdef __x86_64__
 	fldt	(%rcx)
-	fxam			/* Is NaN or +-Inf?  */
+	fxam			/* Is NaN or +-Inf or +-0?  */
 	fstsw   %ax
 	movb    $0x45, %dh
 	andb    %ah, %dh
 	cmpb    $0x05, %dh
 	je      1f		/* Is +-Inf, jump.  */
 	cmpb	$0x40, %dh
-	je	2f		/* Is +-Inf, jump.  */
+	je	2f		/* Is +-0, jump.  */
 
 	fxtract
 	pushq	%rax
@@ -47,14 +47,14 @@ __MINGW_USYMBOL(ilogbl):
 /* I added the following ugly construct because ilogb(+-Inf) is
    required to return INT_MAX in ISO C99.
    -- jakub@redhat.com.  */
-	fxam			/* Is NaN or +-Inf?  */
+	fxam			/* Is NaN or +-Inf or +-0?  */
 	fstsw   %ax
 	movb    $0x45, %dh
 	andb    %ah, %dh
 	cmpb    $0x05, %dh
 	je      1f		/* Is +-Inf, jump.  */
 	cmpb	$0x40, %dh
-	je	2f		/* Is +-Inf, jump.  */
+	je	2f		/* Is +-0, jump.  */
 
 	fxtract
 	pushl	%eax


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ilogbl(0.0L) value is wrong
  2019-12-17 14:04   ` Bruno Haible
@ 2019-12-17 15:41     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2019-12-17 15:41 UTC (permalink / raw)
  To: Bruno Haible; +Cc: cygwin

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

On Dec 17 12:04, Bruno Haible wrote:
> Hi Corinna,
> 
> > 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 can't test it easily.

The code is in the Cygwin 3.1.0-1 release.

> But the code looks good; only the comments could be improved; patch attached.

The comments are the same as in glibc :)


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-17 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12 12:00 ilogbl(0.0L) value is wrong Bruno Haible
2019-12-16 10:21 ` Corinna Vinschen
2019-12-17 14:04   ` Bruno Haible
2019-12-17 15:41     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).