[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 18:09:11 -0400 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux) |
Andreas Schwab <schwab@suse.de> wrote:
> prj@po.cwru.edu (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 have to be performed in unsigned arithmetic
and then adjusted for the proper sign, range chaecking, etc., to get
signed results.
paul
- Bash arithmetic doesn't give error message on wrap., Richard Neill, 2007/04/27
- Re: Bash arithmetic doesn't give error message on wrap., Chet Ramey, 2007/04/28
- Re: Bash arithmetic doesn't give error message on wrap., Richard Neill, 2007/04/28
- Re: Bash arithmetic doesn't give error message on wrap., Bob Proulx, 2007/04/29
- Re: Bash arithmetic doesn't give error message on wrap., Richard Neill, 2007/04/29
- Re: Bash arithmetic doesn't give error message on wrap., Andreas Schwab, 2007/04/30
- Re: Bash arithmetic doesn't give error message on wrap., Bob Proulx, 2007/04/30
- Re: Bash arithmetic doesn't give error message on wrap., Richard Neill, 2007/04/30
- Re: Bash arithmetic doesn't give error message on wrap., Paul Jarc, 2007/04/30
- Re: Bash arithmetic doesn't give error message on wrap., Andreas Schwab, 2007/04/30
- Re: Bash arithmetic doesn't give error message on wrap.,
Paul Jarc <=
- Re: Bash arithmetic doesn't give error message on wrap., Paul Jarc, 2007/04/30