Path: utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!agate!linus!linus!sdimax2!jrv From: jrv@sdimax2.mitre.org (VanZandt) Newsgroups: comp.lang.c Subject: Re: Why do most C compilers poxily round towards zero ? Message-ID: <122954@linus.mitre.org> Date: 11 Oct 90 13:34:26 GMT References: <1990Oct9.230928.27552@arp.anu.oz.au> Sender: usenet@linus.mitre.org Lines: 16 In article peter@ficc.ferranti.com (Peter da Silva) writes: >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. > >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