Re:math operation

Fully featured PIC compilers available on Windows, Linux, and macOS.
Post Reply
Author
Message
adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re:math operation

#1 Post by adu@love » 23 Nov 2022 12:18

/
"a=a *(52/60);" if i scale this up mean avoid fraction 0.8666667 *1000000 say j=a; a=8666667;
a=a*(52/60)*1000000;
a=8666667;
j=a;
if(a>=52&& a<100&&j>=8666667){
portc.f1=1;
or :roll: if ido it like this a=a*52;a/60;
a>=0.8666667
tel me which is correct
thanks

sgssn
Posts: 35
Joined: 13 Sep 2021 16:24

Re: Re:math operation

#2 Post by sgssn » 23 Nov 2022 13:36

Hi
your question: "what is correct" is difficult to answer. It seems to me, that you want to use integer operations. If you would use float or double your problem is smaller. Nevertheless a problem will remain: A uP can not really calculate in decimal. So a fault in your operations will remain.

Ok, when you use integer calculations you have to avoid numbers that create a zero instead of a number not equal to zero: 52/60=0. You know that. So you can multiply 52 by 1000 for example. But in that case you have to check how you defined your variable a to not overflow when multiplying.

But why dont you try for yourself to find the write way for these calculations with relvant examples? If you get the write results, you found the write way to do these operations.

Gehard

adu@love
Posts: 8
Joined: 12 Nov 2022 09:27

Re: Re:math operation

#3 Post by adu@love » 23 Nov 2022 15:28

thank you gehard but iam stuk :roll: :roll: :roll:

Post Reply

Return to “PIC AI compilers”