Path: utzoo!attcan!uunet!jarthur!bridge2!mips!swrinde!ucsd!sdd.hp.com!zaphod.mps.ohio-state.edu!lavaca.uh.edu!menudo.uh.edu!sugar!ficc!peter From: peter@ficc.ferranti.com (Peter da Silva) Newsgroups: comp.lang.c Subject: Re: Why do most C compilers poxily round towards zero ? Message-ID: Date: 10 Oct 90 18:36:38 GMT References: <1990Oct9.230928.27552@arp.anu.oz.au> Reply-To: peter@ficc.ferranti.com (Peter da Silva) Organization: Xenix Support, FICC Lines: 9 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!. 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@ferranti.com