nexttowardl for ppc64el generates wrong results

Bug #1831808 reported by Hubert Tong
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

On PPC, the non-IEEE 128-bit long double is represented as a pair of doubles. This means that for 1.L, the next representable value in the direction of 2.L should be 1.L + DBL_EPSILON. The nexttowardl function does not seem to produce such a result.

To reproduce, compile and link the following C program and run the resulting executable. The actual output and the expected output is provided below.

### SOURCE (<stdin>):
long double nexttowardl(long double, long double);
int printf(const char *, ...);

int main(void) {
  long double eps = nexttowardl(0.L, 1.L);
  long double ans = nexttowardl(1.L, 2.L);
  long double ref = 1.L + eps;
  typedef unsigned char *ucp;
  for (ucp p = (ucp)&ref; p < (ucp)&1[&ref]; ++p) {
    printf("%02hhx", *p);
  }
  printf("\n");
  for (ucp p = (ucp)&ans; p < (ucp)&1[&ans]; ++p) {
    printf("%02hhx", *p);
  }
  printf("\n");
}

### COMPILER INVOCATION:
gcc -xc - -lm

### RUN OUTPUT:
000000000000f03f0100000000000000
000000000000f03f0000000000006039

### EXPECTED OUTPUT:
000000000000f03f0100000000000000
000000000000f03f0100000000000000

### VERSION INFO:
> lsb_release -rd
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Return: 0x00:0

> apt-cache policy libc6
libc6:
  Installed: 2.23-0ubuntu7
  Candidate: 2.23-0ubuntu11
  Version table:
     2.23-0ubuntu11 500
        500 http://ports.ubuntu.com/ubuntu-ports xenial-updates/main ppc64el Packages
     2.23-0ubuntu10 500
        500 http://ports.ubuntu.com/ubuntu-ports xenial-security/main ppc64el Packages
 *** 2.23-0ubuntu7 100
        100 /var/lib/dpkg/status
     2.23-0ubuntu3 500
        500 http://ports.ubuntu.com/ubuntu-ports xenial/main ppc64el Packages
Return: 0x00:0

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.