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

2007-04-29 Thread Bob Proulx
Richard Neill wrote:
  b)Consistent with other cases, where bash does give warnings. For example:
 
 $ X=$((3+078))
 bash: 3+078: value too great for base (error token is 078)
 $ echo $?
 1

That is not really a comparable case.  The problem there is that the
leading zero specifies an octal constant and the 8 cannot be converted
to octal.  The 3+ part is just a distraction.

  echo $((08))
  bash: 08: value too great for base (error token is 08)

Bob


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


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

2007-04-29 Thread Richard Neill



Bob Proulx wrote:

Richard Neill wrote:

 b)Consistent with other cases, where bash does give warnings. For example:

$ X=$((3+078))
bash: 3+078: value too great for base (error token is 078)
$ echo $?
1


That is not really a comparable case.  The problem there is that the
leading zero specifies an octal constant and the 8 cannot be converted
to octal.  The 3+ part is just a distraction.

  echo $((08))
  bash: 08: value too great for base (error token is 08)

Bob



Are you sure this isn't comparable? After all, in both cases, the user 
has submitted something to which bash cannot give a sensible answer. In 
the integer-overflow case, bash simply returns the wrong answer, with no 
warning. But in the octal case, bash (quite correctly, and helpfully) 
prints a warning.


If bash were to be consistent, then it should display no error message 
in the case of $((3+078)); it should either Do what I mean  [evaluate 
3 + 078 as 0103, treating 78 as 7 *8 + 8], or Do something daft [eg 
evaluate as 073  (treating 8 as an integer-overflow in the units place, 
which is not checked for)]


There's obviously an advantage to the user in being warned when an 
integer overflow occurs; is there any possible downside (apart from a 
couple of extra lines of code?


Richard


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash