Problem with Compiler PIC
Moderator: Benj
- 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
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 41
- Joined: Sun Mar 01, 2020 1:39 pm
- Has thanked: 1 time
- Been thanked: 2 times
- Contact:
Re: Problem with Compiler PIC
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
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
- 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
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel