public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/30040] New: nextafter(0.0, 1.0) does not correctly set errno
@ 2023-01-24 10:47 pascal_cuoq at hotmail dot com
2023-01-24 10:47 ` [Bug math/30040] " pascal_cuoq at hotmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pascal_cuoq at hotmail dot com @ 2023-01-24 10:47 UTC (permalink / raw)
To: glibc-bugs
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug math/30040] nextafter(0.0, 1.0) does not correctly set errno
2023-01-24 10:47 [Bug math/30040] New: nextafter(0.0, 1.0) does not correctly set errno pascal_cuoq at hotmail dot com
@ 2023-01-24 10:47 ` pascal_cuoq at hotmail dot com
2023-03-08 17:23 ` schwab@linux-m68k.org
2023-03-08 17:43 ` pascal_cuoq at hotmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: pascal_cuoq at hotmail dot com @ 2023-01-24 10:47 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30040
Pascal Cuoq <pascal_cuoq at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://sourceware.org/bugz
| |illa/show_bug.cgi?id=6799
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug math/30040] nextafter(0.0, 1.0) does not correctly set errno
2023-01-24 10:47 [Bug math/30040] New: nextafter(0.0, 1.0) does not correctly set errno pascal_cuoq at hotmail dot com
2023-01-24 10:47 ` [Bug math/30040] " pascal_cuoq at hotmail dot com
@ 2023-03-08 17:23 ` schwab@linux-m68k.org
2023-03-08 17:43 ` pascal_cuoq at hotmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2023-03-08 17:23 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30040
--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
errno is only intented to be set on underflow when the result is zero, as
explained in commit 85422c2acba83852396c9d9fd22ff0493e3606fe.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug math/30040] nextafter(0.0, 1.0) does not correctly set errno
2023-01-24 10:47 [Bug math/30040] New: nextafter(0.0, 1.0) does not correctly set errno pascal_cuoq at hotmail dot com
2023-01-24 10:47 ` [Bug math/30040] " pascal_cuoq at hotmail dot com
2023-03-08 17:23 ` schwab@linux-m68k.org
@ 2023-03-08 17:43 ` pascal_cuoq at hotmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: pascal_cuoq at hotmail dot com @ 2023-03-08 17:43 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=30040
--- Comment #2 from Pascal Cuoq <pascal_cuoq at hotmail dot com> ---
I see.
In this case the man page that can currently be read at
https://man7.org/linux/man-pages/man3/nextafter.3.html is wrong, since it
describes the behavior as:
If x is not equal to y, and the correct function result would be
subnormal, zero, or underflow, a range error occurs, and either
the correct value (if it can be represented), or 0.0, is
returned.
But this of course is not Glibc's fault (chuckle).
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-08 17:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 10:47 [Bug math/30040] New: nextafter(0.0, 1.0) does not correctly set errno pascal_cuoq at hotmail dot com
2023-01-24 10:47 ` [Bug math/30040] " pascal_cuoq at hotmail dot com
2023-03-08 17:23 ` schwab@linux-m68k.org
2023-03-08 17:43 ` pascal_cuoq at hotmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).