Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!newsfeed.x-privat.org!feeder.news.tin.it!spool.news.tin.it!not-for-mail From: "io_x" Newsgroups: comp.lang.java.programmer,comp.lang.c References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> <3797038f-22d1-40b2-8c12-60db5a0976b8@t5g2000yqj.googlegroups.com> <4e1bf1bc$0$15671$4fafbaef@reader2.news.tin.it> Subject: Re: Arithmetic overflow checking Date: Tue, 12 Jul 2011 13:18:13 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Lines: 71 Message-ID: <4e1c2d07$0$15665$4fafbaef@reader2.news.tin.it> Organization: TIN.IT (http://www.tin.it) X-Comments: Please send technical notifications to newsmaster@tin.it NNTP-Posting-Host: 213.45.245.106 X-Trace: 1310469384 reader2.news.tin.it 15665 213.45.245.106:15359 X-Complaints-To: Please send abuse reports to abuse@retail.telecomitalia.it Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6114 comp.lang.c:8168 "tm" ha scritto nel messaggio news:e7b7711c-93d5-477e-a470-21386854ff6f@j15g2000yqf.googlegroups.com... > > I think there are two things: > > > 1. range checks (like value fits in [0,18]). > > 2. check if an 32-bit (or 8-bit, 16-bit, 64-bit, ...) > > computation overflows. there is anhother one, the one i think could be right 3. consider operation on varible saturantion for example here unsigned are 32 bits range 0..0FFFFFFFFh than consider to each operation overflow saturate its variable for example unsigned32bitsSpecial a; a=9; a+=0xFFFFFFFA; ; here 'a' has value 0FFFFFFFFh because += overflow 'a'; it is as double in the standard C that has +INF so allowed range of not overflow 32Bit variable are 0..0xFFFFFFFE varible in overflow or +INF is 0xFFFFFFFF so if a=INF if b,c,r,m are saturabile variables b+=a, c-=a r/=a m*=a all overflow b,c,r,m and at end b==c==r==m==INF etc etc > the carry flag for 2^n word is ok for detect overflow >Yes, but it must be checked after every operation. >A hardware that triggers an interrupt, would save this >extra checks. >Unchecked signed integer operations i refer only to unsigned, not negative number. i never use it [saturate variables] i like carry flag and check for overflow too disclaimer: i can wrong on all this i'm just an hobby programmer > are used, because of >performance reasons. Many people don't care about correct >results, as long as they have maximum performance. >With >hardware support there would be no performance loss. So >there would be no excuse to accept wrong results. >Greetings Thomas Mertes >-- >Seed7 Homepage: http://seed7.sourceforge.net >Seed7 - The extensible programming language: User defined statements >and operators, abstract data types, templates without special >syntax, OO with interfaces and multiple dispatch, statically typed, interpreted or compiled, portable, runs under linux/unix/windows.