[comp.sys.mac.programmer] THINK C conversion problem: double<->unsigned long int

boeheim@lindy.Stanford.EDU (Chuck Boeheim) (01/24/90)

I have found a problem with THINK C 4.0 when using 
unsigned long ints and doubles.  When an unsigned 
long int is assigned to a double on a machine that
has a 68881 coprocessor, (and you use the 68881 code
generation option), the long int is treated as signed,
rather than unsigned.  If your int has a magnitude 
greater than 2**31 (the MSB is 1), you will end up with
a negative floating point number.
 
  unsigned long int i = 0x80000000;
  double f;

  f = i;    /* Incorrect when compiled for a 68881 */

This problem does not occur with unsigned short integers,
or if you do not use 68881 code generation.

There are a number of bypasses.  If anyone cares, send me
mail.  Symantec promised me that they would fix the problem
in the next release of the compiler.  They also told me
that this problem happens with assignments in the opposite
direction too, though I did not verify that.