64 bits values or 32 bits

J

jim hyden

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("~") ;
}
 
S

SG

[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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top