Why do most C compilers poxily round towards zero ?

Henry Spencer henry at zoo.toronto.edu
Thu Oct 11 02:25:00 AEST 1990


In article <1990Oct9.230928.27552 at arp.anu.oz.au> peterf at arp.anu.oz.au (Peter Fletcher) writes:
>One of the most frustrating things about using floating point in C is the
>poxy way rounds floating point numbers towards zero instead of -infinity.

Unfortunately, this is generally a property of the hardware, introduced
mostly for consistency with the FORTRAN spec, which specifically calls
for rounding toward zero.

>I don't think this policy is in any of the C specifications...

Alas, not so.  ANSI C specifies that conversion from floating-point to
integer format discards the fraction.

However, all is not hopelessly lost, because ANSI C also does provide
the floor() function, and puts enough constraints on library functions
that smart compilers can inline them for speed.

>I think with Suns and Apollos you can tell the floating point hardware
>to use a different rounding mode, but it seems that both methods are
>completely different and probably not compatible with anybody else.
>Is there a reasonably standard Unix way to do this ?

Unfortunately, no.  We need better support of IEEE floating-point facilities
in our programming languages (and, to some extent, our operating systems).
-- 
Imagine life with OS/360 the standard  | Henry Spencer at U of Toronto Zoology
operating system.  Now think about X.  |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list