Why do most C compilers poxily round towards zero ?

Peter da Silva peter at ficc.ferranti.com
Thu Oct 11 04:36:38 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.

The same problem exists with the modulus operator. Mathematically, the
modulus operator !A mod B! should produce a result in the range !0..B-1!.
In fact, it produces a result in the range !1-B..B-1!. This means to do
anything useful with it, when you don't know the sign of !A!, you need
to calculate !(A % B + B) % B! or !(A<0)?((-A)%B):(A%B)!.
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.   'U`
peter at ferranti.com



More information about the Comp.lang.c mailing list