[Bug 299389] [libm] nextafter[fl] and nexttoward[fl] return incorrect results for MAX value depending on rounding mode

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 14 Oct 2026 17:00:11 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=299389

            Bug ID: 299389
           Summary: [libm] nextafter[fl] and nexttoward[fl] return
                    incorrect results for MAX value depending on rounding
                    mode
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: kargl@FreeBSD.org

While scanning the openlibm bugs, I found

https://github.com/JuliaMath/openlibm/issues/361

which contains code that shows FreeBSD libm (may?) produces
wrong results.  For example, the openlibm bug states
that with FE_UPWARD the following code should return
-inf, but it does not!  [Note, I have not looked at
any of the drafts I have of the C standard to determine
what the correct behavior is.]

% cat next.c
int
main(void)
{
   int rnd;
   double x, y;
   x = -DBL_MAX;
   rnd = fegetround();
   fesetround(FE_UPWARD);
   y = nextafter(-DBL_MAX, -INFINITY);
   fesetround(rnd);
   printf("nextafter(%la, -inf) = %le %la\n", x, y, y);
   return 0;
}

% cc -o z next.c -lm && ./z
nextafter(-0x1.fffffffffffffp+1023, -inf) = -1.797693e+308
-0x1.fffffffffffffp+1023

-- 
You are receiving this mail because:
You are the assignee for the bug.