floting-point => integral conversions and rounding

uunet!osf.org!meissner uunet!osf.org!meissner
Tue Dec 21 09:03:54 PST 1993


| 
| There's been a discussion recently in the comp.lang.c++ newsgroup regarding
| what happens when a floating-point value is converted into an integral
| value.
| 
| Much to my surprize, I found that the ISO C standard and the IEEE 754
| standard are in direct conflict regarding what is supposed to happen for
| such conversions.
| 
| The C standard says that "...the fractional part is discarded."  (I think
| that may be just a bit ambiguous in the case of negative numbers... but
| we'll just pass on that for the moment.)
| 
| Anyway, the IEEE 754 standard says that the default rounding which must
| apply to such conversions is "round to nearest".
| 
| Is it just me, or does this direct conflict bother anybody else?

This was an explicit decision of the ANSI C committee, since the
original draft of C (ie, appendix A of K&R) was rather specific in how
floating -> integer conversions were done.  There are a few places
where standards conflict (another is '\n' combining both linefeed and
carriage return functions).  LIA it seems will be yet another issue.

--
Michael Meissner	email: meissneraosf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Old hackers never die, their bugs just increase.



More information about the Numeric-interest mailing list