bug-bash
[Top][All Lists]
Advanced

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

Re: Bash arithmetic doesn't give error message on wrap.


From: Paul Jarc
Subject: Re: Bash arithmetic doesn't give error message on wrap.
Date: Mon, 30 Apr 2007 16:32:58 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux)

bob@proulx.com (Bob Proulx) wrote:
> On some cpus the result is done one way and on others the result is
> done a different way.  It is in these cases where typically POSIX
> would give up and declare it undefined behavior.

Yes, and those are exactly the cases where a message would be helpful,
to let the user know that the result is not portable, and does not
necessarily indicate what the user thinks it does.

Undefined behavior makes sense for C, since C is essentially a
"portable assembly language".  For a higher-level language, it makes
considerably less sense.  And in any case, it does not require the
implementation to be unhelpful.

> About the only way for bash to avoid it would be to include a full
> arbitrary precision math library to evaluate these expressions
> itself.

It depends on the goal.  If the goal is to produce a mathematically
correct result, then yes.  But if the goal is only to detect overflow
and print a warning, then that can still be done without arbitrary
precision.


paul




reply via email to

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