This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

[C51]Bug report: signed char divided by power of 2

Bug fact: Following code cannot get right results.

#include "SST89x5xxRD2.H"

signed char x,y,z;

void main()
{
        x = -15;
        y = x / 4;
        z = x % 4;

        while(1);
}

y = -4 and z = -3, while y should be -3...

Reason: Compiler automatically generates RRC for division by power of 2. For a SIGNED CHAR, this could produce unexpected rounding results.

Solution: If a signed char is divided by power of 2, DO NOT use RRC in this case.