help-gawk
[Top][All Lists]
Advanced

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

Re: Make division by zero legal


From: Andrew J. Schorr
Subject: Re: Make division by zero legal
Date: Wed, 4 Aug 2021 08:49:54 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Aug 03, 2021 at 11:22:30PM -0500, Neil R. Ormos wrote:
> If you do conform the -M behavior for attempts to
> divide by zero, you might also consider conforming
> the behavior when sqrt() and log() are called on a
> negative argument.  Without -M, gawk prints a
> warning.  With -M, no warning is printed.  (Also,
> the sign of the NaN result changes; I don't know
> if the sign is meaningful.)  I haven't tried the
> trig functions.
> 
> 
> (I don't know why divide-by-zero provokes a fatal
> error but sqrt(-2) merits only a warning, but that
> seems to have been the rule for a long time.)
> 
>                            sqrt(-2)    sqrt(-2)    1/0        1/0
> Awk Version                Result      Warning     Result     Error
> ========================   ==========  ==========  =========  =========
> ("original") awk   [1]     1           no          <none>     fatal
> BusyBox Awk        [2]     nan         no          <none>     fatal
> mawk               [3]     -nan        no          inf        no
> Gawk 3.1.7         [4]     -nan        warning     <none>     fatal
> Gawk 4.1.4         [5]     -nan        warning     <none>     fatal
> Gawk 4.1.4 with -M [6]     nan         no          inf        no
> Gawk 5.1.0         [7]     -nan        warning     <none>     fatal
> Gawk 5.1.0 with -M [8]     +nan        no          +inf       no
> ========================   ==========  ==========  =========  =========

Ah, OK, thanks, the warnings are easy to add for log and sqrt, but it's
not as easy to fix the -nan vs +nan results, since -nan comes from
the glibc sqrt function, whereas +nan comes from mpfr_sqrt.

Regards,
Andy



reply via email to

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