Oligierd,

I am using sdcc-2.5.4 and getting expected results with the following code:

typedef unsigned short int      uint16_t;
typedef short int               int16_t;

extern  int     printf(char *fmt, ...);

int main(void)
{
    int
        i;
    uint16_t
        ui1, ui2, ui3;
    int16_t
        i1, i2, i3;

    i2 = 5;
    ui2 = 5;

    for (i = 20; i < 34; i++)
    {
        i1 = i;
        i3 = i1 / i2;
        printf("i1 %d i2 %d i3 %d  ", i1, i2, i3);

        ui1 = i + 1;
        ui3 = ui1 / ui2;
        printf("%d ui2 %d ui3 %d\n", ui1, ui2, ui3);
    }
    return(0);
}

George


On Thu, 2006-05-04 at 15:37 -0400, Olgierd Eysymontt wrote:
Hi, I'm trying a routine to divide two ints woth extrange results, I've
tried with signed and unsigned ints ant the results are the same,
depending of the numbers the results are correct or just '-1'. For
testing purposes I made a small program that sends the numbers to a
serial port and this is what I get : 

(i1,i2,i3 are ints, ui1, ui2,ui3 are unsigned ints and the  operation is
i3=i1/i2, where i3 increases each cicle and i2 = 5 always)


i1 20 i2 5 i3 -1   ui1 21 ui2 5 ui3 -1
i1 21 i2 5 i3 4   ui1 22 ui2 5 ui3 4
i1 22 i2 5 i3 -1   ui1 23 ui2 5 ui3 -1
i1 23 i2 5 i3 4   ui1 24 ui2 5 ui3 4
i1 24 i2 5 i3 -1   ui1 25 ui2 5 ui3 -1
i1 25 i2 5 i3 5   ui1 26 ui2 5 ui3 5
i1 26 i2 5 i3 -1   ui1 27 ui2 5 ui3 -1
i1 27 i2 5 i3 5   ui1 28 ui2 5 ui3 5
i1 28 i2 5 i3 -1   ui1 29 ui2 5 ui3 -1
i1 29 i2 5 i3 5   ui1 30 ui2 5 ui3 6
i1 30 i2 5 i3 -1   ui1 31 ui2 5 ui3 -1
i1 31 i2 5 i3 6   ui1 32 ui2 5 ui3 6
i1 32 i2 5 i3 -1   ui1 33 ui2 5 ui3 -1
i1 33 i2 5 i3 6   ui1 34 ui2 5 ui3 6

When i1 is even the result is always -1, when is odd the answer is
correct, and in the xase of unsigned ints, it's the other way, the ui1
is even the result is ok.

Any clue ?

Thanks in advance

Olgierd




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user