Problem with Compiler PIC

Moderator: Benj

Post Reply
RABO2320
Posts: 41
Joined: Sun Mar 01, 2020 1:39 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Problem with Compiler PIC

Post by RABO2320 »

Mistake in calculation after compile
Mistake in calculation.rar
with Protuos simulation
(19.55 KiB) Downloaded 169 times
-1 MOD 16 = 15

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem with Compiler PIC

Post 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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Problem with Compiler PIC

Post by LeighM »

What does it print on actual target hardware?
Thanks

RABO2320
Posts: 41
Joined: Sun Mar 01, 2020 1:39 pm
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Problem with Compiler PIC

Post 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
:!:

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Problem with Compiler PIC

Post 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.

Post Reply