Re: Rounding with Div and Mod operators

Christopher Glaeser <cdg@nullstone.com>
16 May 1999 15:26:59 -0400

          From comp.compilers

Related articles
Rounding with Div and Mod operators william.rayer@virgin.net (William Rayer) (1999-05-09)
Re: Rounding with Div and Mod operators wclodius@aol.com (1999-05-16)
Re: Rounding with Div and Mod operators ucapjab@ucl.ac.uk (Jonathan Barker) (1999-05-16)
Re: Rounding with Div and Mod operators nr@labrador.cs.virginia.edu (Norman Ramsey) (1999-05-16)
Re: Rounding with Div and Mod operators guerby@acm.org (Laurent Guerby) (1999-05-16)
Re: Rounding with Div and Mod operators anton@mips.complang.tuwien.ac.at (1999-05-16)
Re: Rounding with Div and Mod operators Scott.Daniels@Acm.Org (Scott.David.Daniels) (1999-05-16)
Re: Rounding with Div and Mod operators cdg@nullstone.com (Christopher Glaeser) (1999-05-16)
Re: Rounding with Div and Mod operators johan.persson@mbox319.swipnet.se (Johan Persson) (1999-05-16)
Re: Rounding with Div and Mod operators genew@shuswap.net (1999-05-20)
Re: Rounding with Div and Mod operators sofkam@rpi.edu (1999-05-20)
Re: Rounding with Div and Mod operators drh@microsoft.com (Dave Hanson) (1999-05-20)
Re: Rounding with Div and Mod operators anton@mips.complang.tuwien.ac.at (1999-05-20)
Re: Rounding with Div and Mod operators peter.r.wilson@boeing.com (Peter Wilson) (1999-05-20)
[6 later articles]
| List of all articles for this month |

From: Christopher Glaeser <cdg@nullstone.com>
Newsgroups: comp.compilers
Date: 16 May 1999 15:26:59 -0400
Organization: Nullstone Corporation
References: 99-05-039
Keywords: arithmetic, design

> What is interesting about this rule is there seem to be two ways of
> rounding that satisfy it when n or d are negative - either we round
> integers to the next lowest value or we round towards zero.
> My question is: which rounding system is preferred and does it matter?


Which ever rounding direction you choose, make sure the implementation
is correct. Several years ago I looked at the integer divide code
generated by twenty commercial C compilers to fine tune our
performance test suite, and twelve of these compilers generated
incorrect code. The most common defect was related to power-of-two
optimization such that (x / 2) generated different results than (x /
y) when y=2.


Best,
Christopher Glaeser mailto:cdg@nullstone.com
Nullstone Corporation http://www.nullstone.com


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.