Switch flt_mantissa fields from long to uint32_t.
authorGeorge Koehler <xkernigh@netscape.net>
Sat, 5 Nov 2016 21:00:24 +0000 (17:00 -0400)
committerGeorge Koehler <xkernigh@netscape.net>
Sat, 5 Nov 2016 21:00:24 +0000 (17:00 -0400)
commit3bb41d391038f56b74bd5e34a820d31a4dbd658f
tree6975dffa6b21ae1754beaa467f9e8750e64e65c6
parent5c62ec2d8f281901a1ee0ffdcac6d8bf7ce4617c
Switch flt_mantissa fields from long to uint32_t.

This seems to fix an error when flt_arith converts a literal
double-precision float to IEEE format.  For example, 0.5 and 0.75 got
converted to slightly below their correct values.

My host gcc for amd64 has 64-bit long, but flt_arith needs only 32
bits.  The code (at least flt_add.c) can make 32-bit overflows.  Such
overflows would set the higher bits of a 64-bit long, which might
cause problems later.

I need to use uint32_t and not int32_t because the code still uses
long, and the sign extension from int32_t to long would cause
problems.  The mantissa represents a value in [0, 2) that can't be
negative, so unsigned type is better.  Also, signed overflow is
undefined behavior in C, so flt_add.c better make overflows with
uint32_t and not int32_t.

This commit doesn't touch lang/cem/libcc.ansi/stdlib/ext_fmt.h which
continues to use unsigned long for its mantissa fields.
modules/src/flt_arith/flt_arith.h