Page 1 of 1
Problem with Compiler PIC
Posted: Mon Mar 02, 2020 12:56 pm
by RABO2320
Mistake in calculation after compile
-1 MOD 16 = 15
Re: Problem with Compiler PIC
Posted: Mon Mar 02, 2020 1:15 pm
by Benj
Hello,
That sounds correct to me, what are you expecting?
If you wanted it to give you -1 then first check to see if the value is negative and if it is then flip it to be positive then do the mod function.
if (S < 0)
{
bNeg = 1
Sp = 0 - S
}
else
{
bNeg = 0
Sp = S
}
T = Sp MOD 16
Re: Problem with Compiler PIC
Posted: Mon Mar 02, 2020 1:21 pm
by LeighM
What does it print on actual target hardware?
Thanks
Re: Problem with Compiler PIC
Posted: Wed Mar 04, 2020 1:45 pm
by RABO2320
Hi Benj
Thank you for your solution
I had already obtained this solution.
But there is a problem with the way you said it:
for example;
-1 MOD 16 = 1
This problem should be resolved in the compiler.
But in AVR this is not a problem and:
-1 MOD 16 = -1

Re: Problem with Compiler PIC
Posted: Wed Mar 04, 2020 2:09 pm
by Benj
Sounds like one to pass onto the Microchip compiler team for them to investigate. The AVR compiler is GCC based and as such is more likely to be correct. However reading into it and it seems even for mathematicians there is somewhat of an argument as to what the result should be.