Floating point emulator bug?

David Fiander david at hcr.uucp
Sat Jan 13 00:26:55 AEST 1990

In article <1670 at ctisbv.cti-software.nl> pim at cti-software.nl (Pim Zandbergen)
>Consider the following program:
>    double           a = 2147483648.0;
>    unsigned long    b;
>    b = (unsigned long) a;	/* core dump here */
>    printf("b = %lu\n", b);
>Looks quite legal to me, but it will core dump with a floating
>point exception when compiled for Unix 386 and Xenix 386
>I have used gcc 1.36, ISC's pcc, and SCO Xenix 2.2.3 compilers.
>I have run the programs on ISC 386/ix 2.0.1 and SCO Xenix 386 2.3.1.
>The only working program was produced by the Xenix 286 compiler.
>It will also work on an AT&T 3B2 (with a Math Acceleration Unit)
>I suspect it is a bug in the floating point emulator. Maybe
>the 286 emulator does its own floating point emulation.

This is not a bug in the floating point emulation, it's a bug in the
code generators for all thoso compilers. This is the way
that the '387 really works.  There is a "good" reason for this
though.  When the 387 tries to convert a floating point variable to
an integer variable, if the float won't fit into the integer an
exception is generated.  The problem is that the '387 does not have
an unsigned integer type, and 2147483648 will not fit into a signed
32 bit integer.  The solution is to generate code to convert the
float into a 64 bit integer, and then throw away the top 32 bits (no
problem, eh?).

- David

More information about the Comp.unix.i386 mailing list