ilogbl(NaN) is wrong

Bruno Haible bruno@clisp.org
Tue Apr 18 11:21:33 GMT 2023


POSIX [1] specifies that the return value of the functions ilogbf(), ilogb(),
ilogbl() for a NaN argument should all be the same, namely FP_ILOGBNAN.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/ilogb.html

In Cygwin 3.4.6, the value of ilogbl(NaN) is not right.

How to reproduce:
============================== foo.c ==============================
#include <math.h>
#include <float.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>

int
main (void)
{
  volatile double x1;
  volatile long double x2;
  int y1;
  int y2;

  x1 = 0.0 / 0.0;
  y1 = ilogb (x1);

  x2 = 0.0L / 0.0L;
  y2 = ilogbl (x2);

  printf ("%d %d %d\n", y1, y2, FP_ILOGBNAN);

  if (!(y1 == FP_ILOGBNAN))
    abort ();

  /* This test fails in Cygwin 3.4.6.  */
  if (!(y2 == FP_ILOGBNAN))
    abort ();

  if (!(FP_ILOGBNAN == INT_MAX || FP_ILOGBNAN == INT_MIN))
    abort ();
}
===================================================================
$ gcc -Wall foo.c
$ ./a.exe

Expected output:
2147483647 2147483647 2147483647

Actual output:
2147483647 -2147483648 2147483647
Aborted (core dumped)

Bruno

PS: This is about the same function, but not the argument value, as in
https://cygwin.com/pipermail/cygwin/2019-December/243205.html





More information about the Cygwin mailing list