pim@cti-software.nl (Pim Zandbergen) (01/12/90)
Consider the following program:
main()
{
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.
I do not have a 80387 around to see if this will help.
If some kind soul would want to run this program on either
ISC or SCO with a 80387 and mail me the result,
I'd be grateful eternally.
Be warned, one volunteer with SCO Xenix 2.3.2 had his compiler crashed.
--
Pim Zandbergen domain : pim@cti-software.nl
CTI Software BV uucp : uunet!mcsun!hp4nl!ctisbv!pim
Laan Copes van Cattenburch 70 phone : +31 70 3542302
2585 GD The Hague, The Netherlands fax : +31 70 3512837
david@hcr.uucp (David Fiander) (01/12/90)
In article <1670@ctisbv.cti-software.nl> pim@cti-software.nl (Pim Zandbergen) writes: >Consider the following program: > >main() >{ > 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