PSOC5 division

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I noticed through the following that division by a number much larger than a 1000 doesn't work well unless it is broken into steps. Why is this the case? I assumed that this is something that would be done automatically..

   

pulselen = (Ch1Period - Channel_1_Count)/1000000;

   

sprintf(StringToPrint,"pulselen is %lf s \r\n",pulselen);   ///DOESNT WORK-prints 0.000000
UART_1_PutString(StringToPrint);

   

pulselen = (Ch1Period - Channel_1_Count)/100;
pulselen = pulselen/100;
pulselen = pulselen/100;

   

sprintf(StringToPrint,"pulselen is %lf s \r\n",pulselen);   ///WORKS
UART_1_PutString(StringToPrint);

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Replace /1000000 with /((float) 1000000) or /1000000.0 Compiler treats expression as integer and truncates fractional result to zero

View solution in original post

0 Likes
2 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Replace /1000000 with /((float) 1000000) or /1000000.0 Compiler treats expression as integer and truncates fractional result to zero

0 Likes
Anonymous
Not applicable

Thanks!

0 Likes