Why do most C compilers poxily round towards zero ?

VanZandt jrv at sdimax2.mitre.org
Thu Oct 11 23:34:26 AEST 1990


In article <XTB6WKB at xds13.ferranti.com> peter at ficc.ferranti.com (Peter da Silva) writes:
>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!. 

Amen!  I vote for a library function to calculate the modulus the right
way, which compiler writers could then expand inline.  (Incidently, although
I have several times needed to use a negative first argument, I've
never needed a negative second argument.  Are there really applications
for A mod B where B<0?)

                                   - Jim Van Zandt



More information about the Comp.lang.c mailing list