Divide by zero?

Stefan Bellon sbellon at sbellon.de
Sun Jan 2 13:37:53 PST 2005


John Tytgat wrote:
> In message <4d2716fa2csbellon at sbellon.de>
>           Stefan Bellon <sbellon at sbellon.de> wrote:

> > BTW: i64 is a typedef of "long long int" and pageSize is just int.

> I don't fully trust the v5.54 version of Norcroft when it comes to
> long long code generation.  I've once tried to port IMath (v1.1.0,
> now it is v1.1.5) <URL:http://thayer.dartmouth.edu/~sting/sw/imath/>
> and even with the SharedCLibrary, its test queue results in errors. 
> With the UnixLib equivalent routines, the situation is better but
> still not perfect. I haven't fully investigated what the real
> remaining issues were so I can not blame the compiler for sure but
> currently I simply do not trust it.

GnuPG is as you may know based on cryptographic algorithms. Some of
them make heavily use of long long maths. And all test vectors
calculate correctly.

> If you find more evidence around this topic, I'm very much interested
> seeing it.

Well, that's the problem. When I try a simple test case, it works. Oh,
wait, I _do_ have a simple test case:

*type c.mathtest
#include <stdio.h>
int main(void)
{
    long long int a = 0;
    int b = 100;
    a /= b;
    printf("a = %lli\n", a);
}
*cc mathtest.c
Norcroft RISC OS ARM C vsn 5.55 [17 Oct 2003]
*@.mathtest
a = 0
*cc -Wp -c -JUnixLib: -IUnixLib: mathtest.c
Norcroft RISC OS ARM C vsn 5.55 [17 Oct 2003]
*link -o mathtest o.mathtest UnixLib:o.UnixLib
*@.mathtest
a = 100

Try this example as well:

*type c.mathtest
#include <stdio.h>
int main(void)
{
    long long int a = 100;
    int b = 100;
    a /= b;
    printf("a = %lli\n", a);
}

Correct (with SharedCLibrary) is a = 1 but with UnixLib it says a = 0.
So it looks like the division is fundamentally flawed?

This is _clearly_ wrong when using UnixLib but it is correct when using
SharedCLibrary. I tried with Norcroft 5.50 to 5.55 and it's always the
same.

Greetings,
Stefan.

-- 
Stefan Bellon



More information about the gcc mailing list