int64 problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

int64 problem

202 次查看
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 项奖励
2 回复数

194 次查看
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 项奖励

194 次查看
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 项奖励