* strtold does not set errno when it should
@ 2019-12-12 7:37 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2019-12-12 7:37 UTC (permalink / raw)
To: cygwin
POSIX [1] makes it clear that when the value to be returned would cause
underflow, it should set errno to ERANGE.
[1] <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtod.html>
This test case fails with error code 4 on Cygwin 2.9.
========================== foo.c ==========================
#include <stdlib.h>
#include <errno.h>
#include <float.h>
#include <math.h>
int main ()
{
const char input[] = "1E-100000";
char *ptr;
long double result;
errno = 0;
result = strtold (input, &ptr);
if (!(ptr == input + 9))
return 1;
if (!(0.0L <= result && result <= LDBL_MIN))
return 2;
if (signbit (result))
return 3;
if (result == 0.0L && errno != ERANGE)
return 4;
return 0;
}
============================================================
$ gcc -Wall foo.c
$ ./a.exe
$ echo $?
4
The corresponding test case for strtod() / 'double' succeeds.
Bruno
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-12-12 6:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12 7:37 strtold does not set errno when it should Bruno Haible
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).