Web lists-archives.com

Re: Floating point exception in strtod()




Is that 19! ?  Probably doesn't fit precisely into a double.  Does strtold
behave better?

Some implementations throw on unrepresentable numbers, e.g.
https://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrte/index.html

Ken Brown <kbrown@xxxxxxxxxxx> schrieb am Sa., 7. Apr. 2018, 10:40:

> $ cat strtod_test.c
> #include <stdio.h>
> #include <stdlib.h>
> #include <fenv.h>
>
> int
> main ()
> {
>    /* The following number comes from /usr/share/asymptote/ode.asy.  */
>    const char *str = "121645100408832000.0";
>    char *ptr;
>
>    feenableexcept (FE_INVALID);
>    strtod (str, &ptr);
>
>    /* If there was an exception, the following will not get executed.  */
>    printf ("No exception.\n");
> }
>
> $ gcc strtod_test.c
>
> $ ./a
> Floating point exception (core dumped)
>
> [The above was on x86.  On x86_64 there's simply no output.]
>
> I have no idea what's special about the number 121645100408832000.0, but
> the problem goes away if, for example, I replace the leading 1 by 2.
>
> Ken
>
> --
> 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
>
>
>

--
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