comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP>
Subject: Re: Integer Overflow Question.
Date: Mon, 25 Aug 2014 13:44:59 +0000 (UTC)
Date: 2014-08-25T13:44:59+00:00	[thread overview]
Message-ID: <ltfekq$r6g$1@dont-email.me> (raw)
In-Reply-To: 72292a00-d668-4000-94c3-172094ec8dd1@googlegroups.com

On 2014-08-25, austin.obyrne769@btinternet.com <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 <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


  reply	other threads:[~2014-08-25 13:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-25 11:21 Integer Overflow Question austin.obyrne769
2014-08-25 11:46 ` G.B.
2014-08-25 12:58   ` austin.obyrne769
2014-08-25 13:09     ` Simon Clubley
2014-08-25 13:29       ` austin.obyrne769
2014-08-25 13:44         ` Simon Clubley [this message]
2014-08-25 13:34     ` Aay Jay Chan
2014-08-25 15:09       ` austin.obyrne769
2014-08-25 17:02       ` austin.obyrne769
2014-08-25 17:21         ` Simon Wright
2014-08-25 17:56           ` austin.obyrne769
2014-08-25 19:38           ` austin.obyrne769
2014-08-25 17:40         ` Simon Clubley
2014-08-25 18:09           ` austin.obyrne769
2014-08-25 12:20 ` gautier_niouzes
2014-08-25 12:54   ` austin.obyrne769
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox