Arithmetical Big Problem

General discussion on mikroC.
Post Reply
Author
Message
grandegiove
Posts: 79
Joined: 13 Dec 2010 10:34

Arithmetical Big Problem

#1 Post by grandegiove » 26 Jan 2012 15:41

Hi!

I'm a little bit confused.. :(

Im porting a program written in MikroBasic to MikroCPro and I have some big problems with arithmetical operation.

Old program:

Code: Select all

hpianteettaro as longint
numFile as byte
distanza as word
larghezza as word
... 
hpianteEttaro=numFile*100*100000 
hpianteEttaro=hpianteEttaro/(distanza*larghezza)
...


and I haven't any problem with typecasting and after the operation the value of hpianteettaro was ok! :


(numFile*100*100000)/(distanza*larghezza)

example:
(numFile=4,distanza=300,larghezza=160 -> hPianteEttaro=833)

Porting in MikroC:

Code: Select all

unsigned long hpianteettaro;
unsigned short numFile; 
unsigned int distanza as word;
unsigned int larghezza as word;

...

hpianteEttaro=(numFile*100*100000);  
hpianteEttaro=hpianteEttaro/distanza;
hpianteEttaro=hpianteEttaro/larghezza;

...
after these operations hPianteEttaro=0!


the result is the same if I declare every operator like unsigned long!
What I've wrong?

What kind of rules I've to aplly?

Thanks a lot!
Franek

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Arithmetical Big Problem

#2 Post by filip » 27 Jan 2012 09:24

Hi,

According to the following post I see that you have solved your problem :
http://www.mikroe.com/forum/viewtopic.php?f=88&t=46528

Is that correct ?

Regards,
Filip.

Post Reply

Return to “mikroC General”