Re: Rounding with Div and Mod operators

lassehp@imv.au.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
22 May 1999 02:57:53 -0400

          From comp.compilers

Related articles
[10 earlier articles]
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)
Re: Rounding with Div and Mod operators mfinney@lynchburg.net (1999-05-21)
Re: Rounding with Div and Mod operators jmoore@softmoore.com (John I. Moore, Jr.) (1999-05-22)
Re: Rounding with Div and Mod operators lassehp@imv.au.dk (1999-05-22)
Re: Rounding with Div and Mod operators r_barton1@hotmail.com (Barton) (1999-05-22)
Re: Rounding with Div and Mod operators r_barton1@hotmail.com (Barton) (1999-05-27)
Re: Rounding with Div and Mod operators ucapjab@ucl.ac.uk (Jonathan Barker) (1999-05-27)
| List of all articles for this month |

From: lassehp@imv.au.dk (Lasse =?ISO-8859-1?Q?Hiller=F8e?= Petersen)
Newsgroups: comp.compilers
Date: 22 May 1999 02:57:53 -0400
Organization: Information & Media Science, University of Aarhus
References: 99-05-039
Keywords: arithmetic

>[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]


Ada has both a mod operator and a rem operator, probably because the
designers thought hard about this. Quoting from the language reference
manual <http://www.adaic.org/standards/83lrm/html/lrm-04-05.html#4.5.5>:+
>>Integer division and remainder are defined by the relation


        A = (A/B)*B + (A rem B)


where (A rem B) has the sign of A and an absolute value less than the
absolute value of B. Integer division satisfies the identity


        (-A)/B = -(A/B) = A/(-B)


The result of the modulus operation is such that (A mod B) has the sign of
B and an absolute value less than the absolute value of B; in addition,
for
some integer value N, this result must satisfy the relation


        A = B*N + (A mod B)


<<


I guess a search in the literature around the development of Ada will
reveal some of the discussions leading to the inclusion of both mod and
rem.


-Lasse


Post a followup to this message

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