Re: Rounding with Div and Mod operators

wclodius@aol.com (Wclodius)
16 May 1999 14:10:25 -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)
[12 later articles]
| List of all articles for this month |
From: wclodius@aol.com (Wclodius)
Newsgroups: comp.compilers
Date: 16 May 1999 14:10:25 -0400
Organization: AOL http://www.aol.com
References: 99-05-039
Keywords: arithmetic, design

<< Subject: Rounding with Div and Mod operators
From: "William Rayer" <william.rayer@virgin.net>
Date: Sun, May 9, 1999 4:47 PM


I'm writing a compiler for a new language which is to include the
integer division and integer remainder operators (div and mod). I have
some questions about the way these operators do rounding with negative
operands and would appreciate any feedback.


<snip>
[This has been debated at length over the years, and I've found the
argument to be similar to the byte order argument in that there are
advantages and disadvantages to both, but none strong enough to tip
the scales firmly in favor of one or the other. For what it's worth,
Fortran 90 uses round toward zero. -John]
  >>


Precisely because there are arguments either way I would urge against
providing a single solution. For a new language design I would urge
the inclusion of two pairs of operators, e.g., div0 with mod0 and
divinf with modinf. Even Fortran 90 directly provides both options for
the remainder, with the MOD function providing the remainder under
rounding to zero and MODULO the remainder under rounding to minus
infinity, and indirectly provides other options for division by
conversion to REAL and application of ROUND, FLOOR, CEILING, etc.


If providing both pairs of operators is viewed as undesirable for
other reasons, and efficiency is a concern, then Fortran's rules are,
for better or worse, the preferred choice. At least partly because
efficient performance of Fortran has been of importance, and the other
dominant language in performance testing, C, has not defined its
rounding for negative values, virtually all processor are more
efficient rounding towards zero than rounding towards minus
infinity. As a result C9x will define its rounding to be compatible
with Fortran's.


William B. Clodius


Post a followup to this message

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