Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin3!goblin.stu.neva.ru!newsfeed3.funet.fi!newsfeeds.funet.fi!feeder2.news.elisa.fi!fi.sn.net!newsfeed2.tdcnet.fi!news.song.fi!not-for-mail From: Jukka Lahtinen Newsgroups: comp.lang.java.programmer Subject: Re: Arithmetic overflow checking Organization: none References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> X-no-archive: yes Content-Type: text/plain;charset="iso-8859-1" Content-Transfer-Encoding: 8bit Date: Thu, 07 Jul 2011 14:56:10 +0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:lcWxILYtrydUZccAqAJqlQ+h62I= MIME-Version: 1.0 Lines: 17 NNTP-Posting-Host: 81.17.207.67 X-Trace: 1310039916 news.tdc.fi 2831 81.17.207.67:34348 X-Complaints-To: abuse@tdcnet.fi Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5962 rop rop writes: > If I want to have arithmetic-overflow checking in all parts of an > application, > what is the most practical, simple, efficient way to achieve this? > Id like to clutter the code as little a possible... Without knowing anything about your application, I wonder if doing all the arithmetics with the BigInteger class instead of the int or long primitives would help. It shouldn't ever overflow according to the javadocs. Of course you may consider it not being practical and simple, and at least changing all the primitive numbers would mean changes to the code, but I haven't noticed any better suggestion so far. -- Jukka Lahtinen