Bug 44663 - nextafterl() produces incorrect result when 2nd argument is infinite
Summary: nextafterl() produces incorrect result when 2nd argument is infinite
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 7.1
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2001-06-15 03:15 UTC by Trevin Beattie
Modified: 2008-05-01 15:38 UTC (History)
0 users

Clone Of:
Last Closed: 2001-06-15 12:07:32 UTC

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2001:121 normal SHIPPED_LIVE GNU C Library bugfix update 2001-10-04 04:00:00 UTC

Description Trevin Beattie 2001-06-15 03:15:13 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.2-2 i586)

Description of problem:
nextafter(x,y) and friends are supposed to return the next representable
number after X in the direction of Y (unless Y is NaN).  The double and
float versions work correctly, but on the i386 port, the long double
version will instead return Y if Y is +-infinity.

How reproducible:

Steps to Reproduce:
Compile and run the following program:

#include <stdio.h>
#define __USE_ISOC99 1
#include <math.h>

main ()
  long double delta;

  delta = nextafterl (1.0L, INFINITY) - 1.0L;
  printf ("1ulp = %Lg*2^exp\n", delta);
  return (delta < 0.0L);

Actual Results:  1ulp = inf*2^exp

Expected Results:  1ulp = 1.0842e-19*2^exp

Additional info:

I've glanced at glibc-2.2.3/sysdeps/i386/fpu/s_nextafterl.c, but I can't
tell which block of code is being executed, much less where the bug could
be hiding.

In my own port of the function, I simply check the sign of X against (x <
y) (after checking that X and Y are ordered and unequal) and
increment/decrement X accordingly.  There are a few special border cases
depending on the value of X, but the code works regardless of the value of

Comment 1 Jakub Jelinek 2001-06-15 05:19:34 UTC
It is the IA-32 specific NaN check in i386/fpu/s_nextafterl.c
that is broken (IA-32 infinity has the topmost bit in middleword set).
I'll see if I get to fixing it before leaving for vacation today.

Comment 3 Jakub Jelinek 2001-08-08 13:23:23 UTC
This is fixed since glibc-2.2.3-12.

Note You need to log in before you can comment on or make changes to this bug.