issue with ldexp/ldexpf

Paul Zimmermann <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
       Hi,

this issue, reported for 4.3.0, is still in 4.5.0:

https://sourceware.org/pipermail/newlib/2023/020225.html
https://sourceware.org/pipermail/newlib/2024/021013.html (ping ldexp)
https://sourceware.org/pipermail/newlib/2024/021014.html (ldexpf)

The same issue holds also for ldexpl:

#include <stdio.h>
#include <math.h>
#include <fenv.h>

int main()
{
  volatile long double x = 1.0, y;
  while (x * (long double) 0.5 != 0)
    x = x * 0.5;
  printf ("x=%La\n", x);
  fesetround (FE_TONEAREST);
  y = ldexpl (x, -1);
  printf ("FE_TONEAREST:  y=%La\n", y);
  fesetround (FE_TOWARDZERO);
  y = ldexpl (x, -1);
  printf ("FE_TOWARDZERO: y=%La\n", y);
  fesetround (FE_UPWARD);
  y = ldexpl (x, -1);
  printf ("FE_UPWARD:     y=%La\n", y);
  fesetround (FE_DOWNWARD);
  y = ldexpl (x, -1);
  printf ("FE_DOWNWARD:   y=%La\n", y);
}

$ gcc check_ldexpl.c -lm && ./a.out
x=0x0.000000000000001p-16385
FE_TONEAREST:  y=0x0p+0
FE_TOWARDZERO: y=0x0p+0
FE_UPWARD:     y=0x0.000000000000001p-16385
FE_DOWNWARD:   y=0x0p+0

With Newlib :

x=0x0.000000000000001p-16385
FE_TONEAREST:  y=0x0p+0
FE_TOWARDZERO: y=0x0p+0
FE_UPWARD:     y=0x0p+0
FE_DOWNWARD:   y=0x0p+0

Paul Zimmermann
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.