From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: Integer Overflow Question. Date: Mon, 25 Aug 2014 13:44:59 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <9c5de333-276c-4e3a-be5a-4e5a98cdaa1d@googlegroups.com> <440bf1f1-3e98-47ac-b0c0-f73f170a3603@googlegroups.com> <72292a00-d668-4000-94c3-172094ec8dd1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Mon, 25 Aug 2014 13:44:59 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="4608b842eec0cf9a3651ec9bb5890903"; logging-data="27856"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UwX7VYiF5zEfJdxOdymKwSF0tgVM7dqc=" User-Agent: slrn/0.9.9p1 (Linux) Cancel-Lock: sha1:bdVHubudhrgIYuFFO8k47OI6N8c= Xref: number.nntp.dca.giganews.com comp.lang.ada:188653 Date: 2014-08-25T13:44:59+00:00 List-Id: On 2014-08-25, austin.obyrne769@btinternet.com wrote: > On Monday, August 25, 2014 2:09:35 PM UTC+1, Simon Clubley wrote: >> On 2014-08-25, austin.obyrne769@btinternet.com wrote: >> >> > On Monday, August 25, 2014 12:46:01 PM UTC+1, G.B. wrote: >> >> >> On 25.08.14 13:21, austin.obyrne769@btinternet.com wrote: >> >> >> >> > I have had to put a bound on the maximum integer size output of computations at 2^31 which of course is the maximum positive integer that 32-bit computers can handle. >> >> >> >> Would this not be 2^31 - 1? >> >> >> >> Also, how does your program respond when translated with -gnato? >> > >> >>Would this not be 2^31 - 1? - NO >> > >> > The max, POS integer is 2^(32-1) >> > >> >> Signed or unsigned integers ? >> >> > I understand the the max NEG integer is -[2^32-1)+1] >> > >> >> I think you understand incorrectly. The sign bit is a part of the >> 32 bit value so the range you can express is cut approx in half. > > Thanks - I usually remember it in denary as, > > Max Pos. Int = 2147483647 Which is, for a signed 32 bit integer, (2^31) - 1 as G.B. wrote. > Max Neg. Int = -2147483648 > Looking at your original posting, it's now not clear to me if you meant (2^32)-1 or meant 2^(32-1) in your negative example. I took it to be the former, hence my correction. And BTW, there's no +1 there either. From bc: -(2^(32-1)) -2147483648 (The first line is my input to bc; the second line is the answer from bc.) Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world