Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@zoo.toronto.edu (Henry Spencer)
Subject: Re: Why do most C compilers poxily round towards zero ?
Message-ID: <1990Oct10.162500.8354@zoo.toronto.edu>
Organization: U of Toronto Zoology
References: <1990Oct9.230928.27552@arp.anu.oz.au>
Date: Wed, 10 Oct 90 16:25:00 GMT

In article <1990Oct9.230928.27552@arp.anu.oz.au> peterf@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@zoo.toronto.edu   utzoo!henry
