skip to main content
article
Open access

The Euclidean definition of the functions div and mod

Published: 01 April 1992 Publication History

Abstract

The definitions of the functions div and mod in the computer science literature and in programming languages are either similar to the Algol of Pascal definition (which is shown to be an unfortunate choice) or based on division by truncation (T-definition) or division by flooring as defined by Knuth (F-definition). The differences between various definitions that are in common usage are discussed, and an additional one is proposed, which is based on Euclid's theorem and therefore is called the Euclidean definition (E-definition). Its distinguishing feature is that 0 ≤ D mod d < | d | irrespective of the signs of D and d. It is argued that the E- and F-definitions are superior to all other ones in regularity and useful mathematical properties and hence deserve serious consideration as the standard convention at the applications and language level. It is also shown that these definitions are the most suitable ones for describing number representation systems and the realization of arithmetic operations at the architecture and hardware level.

References

[1]
American National Standards Institute. ANSI/MIL-Std 1815 A, Reference Manual for the Ada Programming Language. Alsys, France, Jan. 1983.
[2]
BOUTE, R. Formal description of digital systems. In Methodolog~es for Computer $ystem Design. W. K. Giloi and B. D. Shriver, Eds., North-Holland, Amsterdam, 1985, pp. 291-306.
[3]
BOUTE, R. Funmath: Towards a general formalism for system description in engineering applications. In Advances in Electr~cal Engineering Software, P. P. Silvester, Ed., Sprmger~ Verlag, New York, 1990, pp. 215-226.
[4]
BOUTE, R. On the equivalence of rime-division and frequency-division multiplexing. IEEE Trans. Commun. COM-33, i (Jan. 1985), 97-99.
[5]
BOUTE, R. Representational and denotational semantics of digital systems. IEEE Trans. Comput. 38, 7 (July 1989), 986-999.
[6]
BOU~E, R. Syntactic and semantic aspects of formal system description. M~croprocess~ng and Microprogramming 27 (1989), 155-162.
[7]
CODY, W. J., ET AL. A proposed radix- and word-length-independent standard for fioatingpoint arithmetic. IEEE Micro 4, 4 (Aug. 1984), 86-100.
[8]
COHEN, D. On holy wars and a plea for peace. IEEE Comput. 14, 10 (Oct. 1981), 48-54.
[9]
HERSTEIN, I.N. Top~cs in Algebra. Xerox College Publ., Lexington, Mass., 1964.
[10]
HmFINGER, P.N. Silage Reference Manual, Rev. 1.3. University of California, Berkeley, Dec. 1987.
[11]
ISO/IEC 7185, Information Technology--Programming Languages--PascaL International Standard, 2nd ed., ISO/IEC 7185, 1990 (E).
[12]
JAMES, D. V. Multiplexed buses: The endian wars continue," IEEE Micro 10, 3 (June 1990), 9-21.
[13]
JENSEN, K., AND WmTH, N. Pascal User Manual and Report. 3rd ed., Sprmger-Verlag, New York, 1985.
[14]
KNUTH, D.E. The Art of Computer Programming, Vol. 1: Fundamental Algor~thms. 2nd ed. Addison-Wesley, Reading, Mass., 1972.
[15]
McDoNNELL, E. E Complex fioor. In APL Congress 73, P. Gjerl~v et al., Eds., North-Holland, Amsterdam, 1973, pp. 299-305.
[16]
McDoN~ELL, E. E. Fuzzy residue. In Proceedings of the APL'79 Conference. Rochester, N.Y., June 1979, pp 42-46.
[17]
STEELE, G. L., JR., Arithmetic shifting considered harmful. SIGPLAN Not. 12, 11 (Nov. 1977), 61-68.
[18]
STEELE, G. L., JR., Common LISP: The Language. Digital Press, Billerica, Mass., 1984.
[19]
TURNER, D. Miranda System Manual, Version 1.009. Research Software Ltd., Canterbury, Kent, May 1987.
[20]
VAN WIJNG^ARDEN, A., ET AL. Revised Report on the Algorithmic Language Algol 68. Springer~Verlag, New York, 1976.

Cited By

View all
  • (2024)Design and Analysis of Receiver Coils with Multiple In-Series Windings for Inductive Eddy Current Angle Position Sensors Based on Coupling of Coils on Printed Circuit BoardsSensors10.3390/s2415488024:15(4880)Online publication date: 27-Jul-2024
  • (2024)Experimental Application of a Quasi-Static Adaptive Controller to a Dual Independent Swirl CombustorCombustion Science and Technology10.1080/00102202.2024.2306301(1-34)Online publication date: 8-Feb-2024
  • (2022)SMT solving for the validation of B and Event-B modelsInternational Journal on Software Tools for Technology Transfer (STTT)10.1007/s10009-022-00682-y24:6(1043-1077)Online publication date: 1-Dec-2022
  • Show More Cited By

Recommendations

Reviews

Herbert G. Mayer

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.

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 14, Issue 2
April 1992
171 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/128861
Issue’s Table of Contents

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 01 April 1992
Published in TOPLAS Volume 14, Issue 2

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Euclid's theorem
  2. decimation
  3. div function
  4. hardware description
  5. integer division
  6. interpolation
  7. mod function
  8. number representation
  9. predefined functions
  10. remainder
  11. residue
  12. sampling

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)783
  • Downloads (Last 6 weeks)127
Reflects downloads up to 09 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Design and Analysis of Receiver Coils with Multiple In-Series Windings for Inductive Eddy Current Angle Position Sensors Based on Coupling of Coils on Printed Circuit BoardsSensors10.3390/s2415488024:15(4880)Online publication date: 27-Jul-2024
  • (2024)Experimental Application of a Quasi-Static Adaptive Controller to a Dual Independent Swirl CombustorCombustion Science and Technology10.1080/00102202.2024.2306301(1-34)Online publication date: 8-Feb-2024
  • (2022)SMT solving for the validation of B and Event-B modelsInternational Journal on Software Tools for Technology Transfer (STTT)10.1007/s10009-022-00682-y24:6(1043-1077)Online publication date: 1-Dec-2022
  • (2021)The Functional Nature of Units, With Application to the Decibel in Propagation Calculations [Education Corner]IEEE Antennas and Propagation Magazine10.1109/MAP.2021.310143963:5(131-139)Online publication date: Oct-2021
  • (2021)Rejection- and importance-sampling-based perfect simulation for Gibbs hard-sphere modelsAdvances in Applied Probability10.1017/apr.2021.153:3(839-885)Online publication date: 8-Oct-2021
  • (2021)Improving SMT Solver Integrations for the Validation of B and Event-B ModelsFormal Methods for Industrial Critical Systems10.1007/978-3-030-85248-1_7(107-125)Online publication date: 19-Aug-2021
  • (2020)Verifying and improving Halide’s term rewriting system with program synthesisProceedings of the ACM on Programming Languages10.1145/34282344:OOPSLA(1-28)Online publication date: 13-Nov-2020
  • (2019)Speaking Stata: The last day of the monthThe Stata Journal: Promoting communications on statistics and Stata10.1177/1536867X1987424719:3(719-728)Online publication date: 20-Sep-2019
  • (2019)Translating alloy and extensions to classical BScience of Computer Programming10.1016/j.scico.2019.102378(102378)Online publication date: Dec-2019
  • (2019)Multi-bit robust image steganography based on modular arithmeticMultimedia Tools and Applications10.1007/s11042-018-6195-y78:2(1511-1546)Online publication date: 1-Jan-2019
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media