comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Simple loop with a strange output
Date: Thu, 23 May 2013 07:37:24 -0700 (PDT)
Date: 2013-05-23T07:37:24-07:00	[thread overview]
Message-ID: <96af9cd4-3368-4866-a38e-2514a0a7a54d@googlegroups.com> (raw)
In-Reply-To: <7cd707ce-ebc5-4df1-9ec3-4f99ce87a07d@googlegroups.com>

On Thursday, May 23, 2013 6:53:19 AM UTC-7, Luca Cappelletti wrote:

> do you know what's happening?

Overflow.

The largest possible value of an "integer" type on this platform is (2**31)-1.  So when X hits 2**30 and then you double it, the actual value, 2**31, won't fit in an integer.  If you use the right flags when compiling (I don't remember what they are), this will cause a Constraint_Error to be raised.  But since you didn't use those flags, the result will be whatever the processor returns, which will be -2**31.  Since this is less than 1099999999, it will loop back and try to double it again; now when you double it the processor will return 0, and then you get stuck in an infinite loop.

                          -- Adam

  parent reply	other threads:[~2013-05-23 14:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-23 13:53 Simple loop with a strange output Luca Cappelletti
2013-05-23 13:55 ` Luca Cappelletti
2013-05-23 14:37 ` Adam Beneschan [this message]
2013-05-23 14:41   ` Adam Beneschan
2013-05-23 16:09     ` Luca Cappelletti
2013-05-23 16:40       ` Simon Wright
2013-05-23 21:34         ` Randy Brukardt
2013-05-24  7:21           ` Simon Wright
2013-05-24 12:46           ` Britt
2013-05-23 20:41 ` Dirk Heinrichs
replies disabled

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