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

2007-04-30 Thread Paul Jarc
Andreas Schwab <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] (Paul Jarc) writes: >> result=a*b; >> if (result/a!=b) { report overflow; } > > That won't work, since (signed integer) overflow is undefined in C. A > compiler is allowed to optimize the condition to false. Right, operations would hav

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

2007-04-30 Thread Andreas Schwab
[EMAIL PROTECTED] (Paul Jarc) writes: > Richard Neill <[EMAIL PROTECTED]> wrote: >> I thought testing for overflow was quite simple? >> Isn't it just a case of looking at the carry-bit, and seeing whether it >> gets set? > > That's usually how it's done in assembly. In C, it's somewhat more > co

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

2007-04-30 Thread Paul Jarc
Richard Neill <[EMAIL PROTECTED]> wrote: > I thought testing for overflow was quite simple? > Isn't it just a case of looking at the carry-bit, and seeing whether it > gets set? That's usually how it's done in assembly. In C, it's somewhat more compilcated. For example: result=a*b; if (result/a

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

2007-04-30 Thread Paul Jarc
[EMAIL PROTECTED] (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,

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

2007-04-30 Thread Richard Neill
Bob Proulx wrote: Andreas Schwab wrote: Richard Neill <[EMAIL PROTECTED]> writes: 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, wit

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

2007-04-30 Thread Bob Proulx
Andreas Schwab wrote: > Richard Neill <[EMAIL PROTECTED]> writes: > > 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 > > w

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

2007-04-30 Thread Andreas Schwab
Richard Neill <[EMAIL PROTECTED]> writes: > 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. The answer is not real