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: Chet Ramey
Subject: Re: Bash arithmetic doesn't give error message on wrap.
Date: Sat, 28 Apr 2007 11:25:44 -0400
User-agent: Thunderbird 2.0.0.0 (Macintosh/20070326)

Richard Neill wrote:

> Bash Version: 3.2
> Patch Level: 13
> Release Status: release
> 
> Description:
>          $   echo $((4000000000*4000000000)
>      -2446744073709551616
> 
> Repeat-By:
>     Do some arithmetic in bash $((....)).
>     If the numbers are out of range, the output will be wrong in
>         all sorts of interesting ways. No error message is given.
> 
> Fix:
>         Arbitrary-precision maths would be nice. But at least, could we
>     have an error message if an overflow occurs?
> 
>     The man page says:
>         "Evaluation is done in fixed-width integers with no
>                 check for overflow..."
>     but I'd suggest this represents a bug, not a feature.

I'm comfortable with the current behavior.  POSIX requires that expressions
be evaluated according to the C standard, and that standard leaves the
treatment of integer overflow as undefined.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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