Hi,

I don't know why you get two different results, but neither result is 
correct as a division by 0 is undefined. I could imagine that in the 
case where you specify the calculation explicitly, the calculation is 
done in the compiler, while when you specify the calculation with the 
variables, the calculation is done on at runtime on the microcontroller 
(assuming you run this on actual hardware).

In any case, you should probably check for a division by zero and handle 
it properly (i.e., return the result you need):

if(packetsSend == 0) {
   latest = 0;
} else {
   latest = (100 * packetsLost) / packetsSend;
}

Cheers,
Urs


On 10/04/2010 03:00 PM, wasif masood wrote:
>
> I dont whether its a stupid question or not, but I am stucked in a very
> simple equation,
>
> uint32_t latest
> uint32_t packetsLost
> uint32_t packetsSend
>
> latest =0;
> packetsLost = 0 ;
> packetsSend = 0;
>
> printf("latest:%u\n",latest);printfflush();
>
> latest = 100*packetsLost/packetsSend;
>
> printf("latest:%u\n",latest);printfflush();
>
> out is :
>
> latest : 0
> latest : 65536
>
>
> can any one please tell me what is wrong why after the division its
> giving 65535 where as if I simply do :
>
> latest = 100*0 / 0
>
> output is 0
> Wasif Masood
>
>
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to