bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Overflow to Infinity


From: Eli Zaretskii
Subject: Re: [bug-gawk] Overflow to Infinity
Date: Fri, 06 Jul 2018 11:46:36 +0300

> From: Arnold Robbins <address@hidden>
> Date: Fri, 06 Jul 2018 10:28:57 +0300
> Cc: address@hidden, address@hidden
> 
> I have finally dealt with it.  This is the patch I'd like to
> push shortly.

Thanks.

> +static char *
> +format_nan_inf(double val)
> +{
> +     static char buf[100];
> +
> +     if (isnan(val)) {
> +             sprintf(buf, "%g", val);
> +             if (strcmp(buf, "nan") == 0) // "-nan" or "nan"
> +                     strcpy(buf, "+nan");

This is non-portable.  On MS-Windows, the string you may get is
"1.#IND", not "nan", depending on the version of the C runtime.  It
can also have a leading sign, as in "-1.#IND".

Why do you need to sprintf the value, if it is known that it's a NaN?
Why not do what you do with Inf:

> +     } else if (isinf(val)) {
> +             strcpy(buf, val < 0 ? "-inf" : "+inf");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]