int64 problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

int64 problem

179 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mspahr on Thu Mar 13 14:04:27 MST 2014
I am using LPCXpresso V5.2.6

int64 is not working correctly.
int64var=3352*3352*3352*3352;
I get a warning integer overflow
The answer is 126,245,538,697,216
int 64 is good to 9,223,372,036,854,775,807.
I also tried
int32vara=3352*3352;
int32varb=3352*3352;
int64var=int32vara*int32varb;
got -730001408

0 Kudos
2 Replies

171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bavarian on Fri Mar 14 04:42:52 MST 2014
As mentioned already, it's all about proper casting of constants or variables.
The compiler is not the guilty one.

Regards,
NXP Support Team
0 Kudos

171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Thu Mar 13 14:48:10 MST 2014
Your result can hold large values, your calculation is in 'int' (int32!) only.
Use 3352llu or similar and your problems are gone.
0 Kudos