[Bug math/30040] New: nextafter(0.0, 1.0) does not correctly set errno

pascal_cuoq at hotmail dot com sourceware-bugzilla@sourceware.org
Tue Jan 24 10:47:33 GMT 2023


https://sourceware.org/bugzilla/show_bug.cgi?id=30040

            Bug ID: 30040
           Summary: nextafter(0.0, 1.0) does not correctly set errno
           Product: glibc
           Version: 2.38
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: pascal_cuoq at hotmail dot com
  Target Milestone: ---

The bug is visible as of this writing at https://godbolt.org/z/P1zGr85vs.
The input program and result are attached below.

When https://sourceware.org/bugzilla/show_bug.cgi?id=6799 was fixed by commit
85422c2acba , the execution path where x==0 a few lines above the change was
forgotten.

_____
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include <float.h>
#include <fenv.h>

int main() {
    double v;

    printf("ERANGE = %d\n", ERANGE);

    // nextafter(0., 1.);
    feclearexcept(FE_UNDERFLOW);
    errno = 0;
    v = nextafter(0., 1.);
    printf("\nnextafter(0., 1.) = %a\n", v);
    printf("is subnormal: %d\n", fpclassify(v) == FP_SUBNORMAL);
    printf("errno = %d\n", errno);
    if(fetestexcept(FE_UNDERFLOW))     printf("FE_UNDERFLOW\n");

    // nextafter(DBL_MIN_SUBNORMAL, 1.);
    feclearexcept(FE_UNDERFLOW);
    errno = 0;
    v = nextafter(v, 1.);
    printf("\nnextafter(DBL_MIN_SUBNORMAL, 1.) = %a\n", v);
    printf("is subnormal: %d\n", fpclassify(v) == FP_SUBNORMAL);
    printf("errno = %d\n", errno);
    if(fetestexcept(FE_UNDERFLOW))     printf("FE_UNDERFLOW\n");

    // nextafter(DBL_MIN_SUBNORMAL, 0.);
    feclearexcept(FE_UNDERFLOW);
    errno = 0;
    v = nextafter(0x0.0000000000001p-1022, 0.);
    printf("\nnextafter(DBL_MIN_SUBNORMAL, 0.) = %a\n", v);
    printf("is subnormal: %d\n", fpclassify(v) == FP_SUBNORMAL);
    printf("errno = %d\n", errno);
    if(fetestexcept(FE_UNDERFLOW))     printf("FE_UNDERFLOW\n");

    // nextafter(DBL_MIN, 0.);
    feclearexcept(FE_UNDERFLOW);
    errno = 0;
    v = nextafter(DBL_MIN, 0.);
    printf("\nnextafter(DBL_MIN, 0.) = %a\n", v);
    printf("is subnormal: %d\n", fpclassify(v) == FP_SUBNORMAL);
    printf("errno = %d\n", errno);
    if(fetestexcept(FE_UNDERFLOW))     printf("FE_UNDERFLOW\n");

    // nextafter(1., 2.);
    feclearexcept(FE_UNDERFLOW);
    errno = 0;
    v = nextafter(1., 2.);
    printf("\nnextafter(1., 2.) = %a\n", v);
    printf("is subnormal: %d\n", fpclassify(v) == FP_SUBNORMAL);
    printf("errno = %d\n", errno);
    if(fetestexcept(FE_UNDERFLOW))     printf("FE_UNDERFLOW\n");
}
_________
ERANGE = 34

nextafter(0., 1.) = 0x0.0000000000001p-1022
is subnormal: 1
errno = 0
FE_UNDERFLOW

nextafter(DBL_MIN_SUBNORMAL, 1.) = 0x0.0000000000002p-1022
is subnormal: 1
errno = 34
FE_UNDERFLOW

nextafter(DBL_MIN_SUBNORMAL, 0.) = 0x0p+0
is subnormal: 0
errno = 34
FE_UNDERFLOW

nextafter(DBL_MIN, 0.) = 0x0.fffffffffffffp-1022
is subnormal: 1
errno = 34
FE_UNDERFLOW

nextafter(1., 2.) = 0x1.0000000000001p+0
is subnormal: 0
errno = 0

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list