Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7307 > unrolled thread

64 bits values or 32 bits

Started byjim hyden <netuser501@gmail.com>
First post2011-06-30 14:17 -0700
Last post2011-07-01 18:42 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.c++


Contents

  64 bits values or 32 bits jim hyden <netuser501@gmail.com> - 2011-06-30 14:17 -0700
    Re: 64 bits values or 32 bits Ian Collins <ian-news@hotmail.com> - 2011-07-01 09:52 +1200
    Re: 64 bits values or 32 bits "Paul" <pchristor@yahoo.co.uk> - 2011-07-01 01:01 +0100
    Re: 64 bits values or 32 bits SG <s.gesemann@gmail.com> - 2011-07-01 18:42 -0700

#7307 — 64 bits values or 32 bits

Fromjim hyden <netuser501@gmail.com>
Date2011-06-30 14:17 -0700
Subject64 bits values or 32 bits
Message-ID<9087354f-58c5-480d-b34a-3543ca5bb93f@l9g2000yqk.googlegroups.com>
Hi,

For the 2 first questions (as comments in the code), the code below is
"half- working" on a 64 bits windows 7 laptop running Windev C++. Is
Windev running in 32 bits mode by default?

Without the if statement in this loop it returns 1 or
-4 294 967 295.

In fact, it is now returning 1 for question 2 which is not what I
expect.

With the if statement, the code returns
2 147 483 648 for 32 loops in question 1 and question 2 when it's 33
loops ?

Something wrong with the algorithm in the code???

	while (var_integer > 0)
	{
		cout << "\n" << nb << "\tvar_int : " << var_integer ;
		var_integer *= 2 ;
		nb++ ;
		if (var_integer > 0)
			var_integer2 = var_integer ;
	}


/* 1- Compute a n*2 value for 64 iterations */
/* 2- Maximum integer variable iterations for n*2 */
/* 3- Computer the number of iteration needed to reach the value in
question 1 */
int main()
try
{
        long double var_long_double = 1 ;
        long double var_long_double2 = 1 ;
        unsigned int var_integer = 1 ;
        unsigned int var_integer2 = 1 ;
        int i = 1 ;
        int nb = 1 ;
        // QUESTION 1
        while (i < 64)
        {
                var_long_double *= 2 ;
                i++ ;
        }
        cout << "\n1- Value for 64 iteration : " << var_long_double ;
        //QUESTION 2
        while (var_integer > 0)
        {
                cout << "\n" << nb << "\tvar_int : " << var_integer ;
                var_integer *= 2 ;
                nb++ ;
                if (var_integer > 0)
                        var_integer2 = var_integer ;
        }
        cout << "\n\n2- Number as integer variable for " << nb << "
incrementations : " << var_integer2 ;
        // QUESTION 3
        i = 1 ;
        while (var_long_double >= 0)
        {
                var_long_double /= 2 ;
                if (var_long_double >= 0)
                        var_long_double2 = var_long_double ;
                else
                        break ;
                i++ ;
        }
        cout << "\n3-Number of maximum iteration for i as int " << i
<<
"\n" ;
        cout << "\n\n" ;
        system("pause") ;
        return 0 ;
}

catch (runtime_error e)
{
        cout << e.what() << '\n' ;
        keep_window_open("~") ;
}

catch(...)
{
        cout << "Exiting\n" ;
        keep_window_open("~") ;
}

[toc] | [next] | [standalone]


#7308

FromIan Collins <ian-news@hotmail.com>
Date2011-07-01 09:52 +1200
Message-ID<9749hnFnfiU4@mid.individual.net>
In reply to#7307
On 07/ 1/11 09:17 AM, jim hyden wrote:
> Hi,

What about the answers I gave last time you asked?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#7314

From"Paul" <pchristor@yahoo.co.uk>
Date2011-07-01 01:01 +0100
Message-ID<iuj2pc$1smd$1@adenine.netfront.net>
In reply to#7307
"jim hyden" <netuser501@gmail.com> wrote in message 
news:9087354f-58c5-480d-b34a-3543ca5bb93f@l9g2000yqk.googlegroups.com...
> Hi,
>
> For the 2 first questions (as comments in the code), the code below is
> "half- working" on a 64 bits windows 7 laptop running Windev C++. Is
> Windev running in 32 bits mode by default?
>
> Without the if statement in this loop it returns 1 or
> -4 294 967 295.
>
> In fact, it is now returning 1 for question 2 which is not what I
> expect.
>
> With the if statement, the code returns
> 2 147 483 648 for 32 loops in question 1 and question 2 when it's 33
> loops ?
>
> Something wrong with the algorithm in the code???
>
> while (var_integer > 0)
> {
> cout << "\n" << nb << "\tvar_int : " << var_integer ;
> var_integer *= 2 ;
> nb++ ;
> if (var_integer > 0)
> var_integer2 = var_integer ;
> }
>
>
> /* 1- Compute a n*2 value for 64 iterations */
> /* 2- Maximum integer variable iterations for n*2 */
> /* 3- Computer the number of iteration needed to reach the value in
> question 1 */
> int main()
> try
> {
>        long double var_long_double = 1 ;
>        long double var_long_double2 = 1 ;
>        unsigned int var_integer = 1 ;
>        unsigned int var_integer2 = 1 ;
>        int i = 1 ;
>        int nb = 1 ;
>        // QUESTION 1
>        while (i < 64)
>        {
>                var_long_double *= 2 ;
>                i++ ;
>        }
>        cout << "\n1- Value for 64 iteration : " << var_long_double ;
>        //QUESTION 2
>        while (var_integer > 0)
>        {
>                cout << "\n" << nb << "\tvar_int : " << var_integer ;
>                var_integer *= 2 ;
>                nb++ ;
>                if (var_integer > 0)
>                        var_integer2 = var_integer ;
>        }
>        cout << "\n\n2- Number as integer variable for " << nb << "
> incrementations : " << var_integer2 ;
>        // QUESTION 3
>        i = 1 ;
>        while (var_long_double >= 0)
>        {
>                var_long_double /= 2 ;
>                if (var_long_double >= 0)
>                        var_long_double2 = var_long_double ;
>                else
>                        break ;
>                i++ ;
>        }
>        cout << "\n3-Number of maximum iteration for i as int " << i
> <<
> "\n" ;
>        cout << "\n\n" ;
>        system("pause") ;
>        return 0 ;
> }
>
> catch (runtime_error e)
> {
>        cout << e.what() << '\n' ;
>        keep_window_open("~") ;
> }
>
> catch(...)
> {
>        cout << "Exiting\n" ;
>        keep_window_open("~") ;
> }

Please excuse me if I am missing the point but can't you just use sizeof to 
determine if your varaibles are a different size on a 64-bit implementation? 


--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

[toc] | [prev] | [next] | [standalone]


#7342

FromSG <s.gesemann@gmail.com>
Date2011-07-01 18:42 -0700
Message-ID<df2de243-c530-43cb-8e02-e8cd58303481@fr19g2000vbb.googlegroups.com>
In reply to#7307
On 30 Jun., 23:17, jim hyden <netuser...@gmail.com> wrote:
> [code that invokes undefined behaviour due to overflows]

What is the point of all this?
Can't you just simply query implementation details via the <limits>
and <climits> headers instead?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web