Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
The Euclidean definition of the functions div and mod
Boute R. ACM Transactions on Programming Languages and Systems14 (2):127-144,1992.Type:Article
Date Reviewed: Nov 1 1992

Here is another paper that should have been written decades ago, in which case an existing, widespread incompleteness in programming language design could have been prevented. It points out that in most current programming languages, the elementary arithmetic functions div and mod (for “division” and “remainder”) are defined incorrectly, inconsistently, or not at all for some quadrants. That Euclid wrote the most suitable definition long ago renders this situation in the programming world a bit ludicrous. The paper points out wrong and inconsistent definitions for div and mod functions in several standard languages, discusses options for defining these functions, and compares their respective pros and cons. It also demonstrates that the definition provided by Euclid is most useful for programming, resulting in a strong hint for future machine architects and language designers.

The paper justifies the need for the div and mod functions in programming languages and lists a number of numeric attributes these functions should possess. It then presents a range of definitions for div and mod, starting with ISO Pascal. The Pascal definition is followed by a second definition based on division by truncation (T-definition), a third proposed by Knuth and based on division by flooring (F-definition), and finally Euclid’s definition (E-definition). Once the Pascal definition is shown to be wrong and incomplete except for the restricted case of solely positive operands, it is dropped from further discussion. The paper discusses division and remainder for negative operands and explains desirable properties. It shows the results in graphic form for integer operands and sketches operand and result ranges for real values. Finally, a table compares and weighs all pros and cons, with the convincing conclusion that the E-definition shows the greatest value in terms of numeric attributes and practicality. During the discussion, the author is objective in that he shows the advantages of options other than the E-definition--the front-runner--and considers practical aspects such as variable-word-length number representations, precision considerations, and implementation on physical architectures.

On the surface, the paper is organized poorly; the structure is too complex for a paper less than 20 pages long. There are four levels of structuring, some numeric, some alphabetic, mixing Roman and Arabic, and some parenthesized; the referees should have caught this inconsistency. The editor should have caught the numerous typographical errors. Since the proposed solution is the one defined by Euclid in Alexandria around 300 BC, a literature reference would have been appropriate, but is missing. Occasionally, the author uses terse and mildly obscure mathematical notation that seems to be a subjective preference. To enhance clarity, the author should have offered a table with sample solutions for each definition, each using a consistent range of operands, similar to the way the Ada standard does for the rem and mod functions. The value range should have included an operand pair, for which a desirable property would be violated. The paper does not point out that one of the most widely used languages, C, also specifies the remainder operator % incompletely.

These weaknesses are largely cosmetic or not critical. If we accept that div and mod are essential, the paper serves as an essential reference point. Hopefully, future revisions of standard languages and future programming languages will take this paper into account and finally offer solutions to division and remainder-finding in the way the old Greeks did it. Machine architects who argue that one should exploit the gained nanosecond for their favorite version of division can be appeased by providing additional nonstandard versions of division and remainder-finding in programming languages, similar to the PL/I model. That way, cycle-eager machine architects and correctness-conscious programmers can both be satisfied. Boute’s paper is the needed catalyst for such a future synthesis.

This paper is mandatory reading for anyone amending an existing standard or inventing the next programming language with arithmetic operations. Those who wonder why Ada has both rem and mod operators and why division and remainder-finding for negative operands are undefined in many standard languages will benefit from reading this paper. It is far ahead of virtually all programming language definitions regarding div and mod, yet it is a quarter-century late. The programming community should be grateful for the ideas finally published by Boute in this complete discussion.

Reviewer:  Herbert G. Mayer Review #: CR116308
Bookmark and Share
 
Semantics (D.3.1 ... )
 
 
Computer Arithmetic (G.1.0 ... )
 
 
Data Types And Structures (D.3.3 ... )
 
 
Standards (D.3.0 ... )
 
 
General (D.3.0 )
 
 
Language Constructs and Features (D.3.3 )
 
  more  
Would you recommend this review?
yes
no
Other reviews under "Semantics": Date
The semantics of programming languages: an elementary introduction using structural operational semantics
Hennessy M., John Wiley & Sons, Inc., New York, NY, 1990. Type: Book (9780471927723)
Jul 1 1991
Logic of domains
Zhang G., Birkhäuser Boston Inc., Cambridge, MA, 1991. Type: Book (9780817635701)
Mar 1 1993
A linear-history semantics for languages for distributed programming
Francez N., Lehmann D., Pnueli A. Theoretical Computer Science 32(1-2): 25-46, 1984. Type: Article
Jul 1 1985
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy