[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Make division by zero legal
From: |
Peng Yu |
Subject: |
Re: Make division by zero legal |
Date: |
Tue, 3 Aug 2021 10:34:29 -0500 |
The '/' operator in python/numpy does not even return any warnings.
This should be expected behavior.
>>> y/x
array([ inf, 2. , 1.5 , 1.33333333, 1.25 ])
On 8/3/21, Peng Yu <pengyu.ut@gmail.com> wrote:
> On 8/3/21, Andrew J. Schorr <aschorr@telemetry-investments.com> wrote:
>> On Mon, Aug 02, 2021 at 09:04:52PM -0500, Neil R. Ormos wrote:
>>> Andrew J. Schorr wrote:
>>> > Nethox wrote:
>>>
>>> >> [...]
>>> >> $ gawk -M 'BEGIN { print 1/0; print "workaround" }'
>>> >> +inf
>>> >> workaround
>>>
>>> > I can't speak to why gawk currently crashes on
>>> > division by zero; it does seem odd that -M
>>> > behaves differently.
>>>
>>> Notwithstanding mawk and gawk -M, other awks do
>>> treat division by zero as a fatal error and, like
>>> gawk, have for years.
>>>
>>> I rely on that behavior. Perhaps others do, also.
>>>
>>> Inasmuch as there are several trivial workarounds
>>> available to the OP, I hope his or her proposed
>>> change will not be incorporated into gawk as
>>> default behavior.
>>
>> This is basically a bug in the -M implementation. It needs
>> to be brought in line with the regular non-M behavior to
>> throw a fatal division by zero error. So the "workaround"
>> is not a good long-term plan.
>
> I don't think -M implementation is buggy. It is the 1/0-to-error behavior
> buggy.
>
> 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 ])
>
> --
> Regards,
> Peng
>
--
Regards,
Peng
- Make division by zero legal, Peng Yu, 2021/08/01
- Re: Make division by zero legal, Nethox, 2021/08/02
- RE: Make division by zero legal, Carl Friedberg, 2021/08/03
- Re: Make division by zero legal, Andrew J. Schorr, 2021/08/03
- Re: Make division by zero legal, Neil R. Ormos, 2021/08/04
- Re: Make division by zero legal, Wolfgang Laun, 2021/08/04
- Re: Make division by zero legal, Andrew J. Schorr, 2021/08/04