[Top][All Lists]

[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: Tue, 3 Aug 2021 12:14:56 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Tue, Aug 03, 2021 at 10:32:20AM -0500, Peng Yu wrote:
> I don't think -M implementation is buggy. It is the 1/0-to-error behavior 
> buggy.

Nothing is buggy. This is an implementation choice.

> A warning may be returned (but there should be a way to turn the
> warning off) for division by zero. But a fatal error definitely should
> not be returned in such a case.
> Besides the R example that I provided, python/numpy also allows
> division by zero. Basically, for any package dealing with numerical
> algorithms seriously, they allow division by zero. The fact that awk
> does not allow it suggests that awk is deficient for implementing
> numerical algorithms, which does not have to be so.
> >>> x = np.arange(5)
> >>> y = numpy.arange(start=1, stop=6)
> >>> numpy.true_divide( y, x)
> <stdin>:1: RuntimeWarning: divide by zero encountered in true_divide
> array([       inf, 2.        , 1.5       , 1.33333333, 1.25      ])

But basic Python throws an exception on division by zero:

bash-4.2$ python -c 'x = 5; y = 0; print(x/y)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero

If you would like to implement a numpy library for gawk, you may choose
to handle division by zero differently.


reply via email to

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