Modulo

Last updated

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another (called the modulus of the operation).

Contents

Given two positive numbers a and n, a modulo n (often abbreviated as a mod n) is the remainder of the Euclidean division of a by n, where a is the dividend and n is the divisor. [1]

For example, the expression "5 mod 2" evaluates to 1, because 5 divided by 2 has a quotient of 2 and a remainder of 1, while "9 mod 3" would evaluate to 0, because 9 divided by 3 has a quotient of 3 and a remainder of 0.

Although typically performed with a and n both being integers, many computing systems now allow other types of numeric operands. The range of values for an integer modulo operation of n is 0 to n − 1 (a mod 1 is always 0; a mod 0 is undefined, being a division by zero).

When exactly one of a or n is negative, the basic definition breaks down, and programming languages differ in how these values are defined.

Variants of the definition

In mathematics, the result of the modulo operation is an equivalence class, and any member of the class may be chosen as representative; however, the usual representative is the least positive residue, the smallest non-negative integer that belongs to that class (i.e., the remainder of the Euclidean division). [2] However, other conventions are possible. Computers and calculators have various ways of storing and representing numbers; thus their definition of the modulo operation depends on the programming language or the underlying hardware.

In nearly all computing systems, the quotient q and the remainder r of a divided by n satisfy the following conditions:

(1)

This still leaves a sign ambiguity if the remainder is non-zero: two possible choices for the remainder occur, one negative and the other positive; that choice determines which of the two consecutive quotients must be used to satisfy equation (1). In number theory, the positive remainder is always chosen, but in computing, programming languages choose depending on the language and the signs of a or n. [lower-alpha 1] Standard Pascal and ALGOL 68, for example, give a positive remainder (or 0) even for negative divisors, and some programming languages, such as C90, leave it to the implementation when either of n or a is negative (see the table under § In programming languages for details). a modulo 0 is undefined in most systems, although some do define it as a.

If both the dividend and divisor are positive, then the truncated, floored, and Euclidean definitions agree. If the dividend is positive and the divisor is negative, then the truncated and Euclidean definitions agree. If the dividend is negative and the divisor is positive, then the floored and Euclidean definitions agree. If both the dividend and divisor are negative, then the truncated and floored definitions agree.

As described by Leijen,

Boute argues that Euclidean division is superior to the other ones in terms of regularity and useful mathematical properties, although floored division, promoted by Knuth, is also a good definition. Despite its widespread use, truncated division is shown to be inferior to the other definitions.

Daan Leijen, Division and Modulus for Computer Scientists [5]

However, truncated division satisfies the identity . [6]

Notation

Some calculators have a mod() function button, and many programming languages have a similar function, expressed as mod(a, n), for example. Some also support expressions that use "%", "mod", or "Mod" as a modulo or remainder operator, such as a % n or a mod n.

For environments lacking a similar function, any of the three definitions above can be used.

Common pitfalls

When the result of a modulo operation has the sign of the dividend (truncated definition), it can lead to surprising mistakes.

For example, to test if an integer is odd, one might be inclined to test if the remainder by 2 is equal to 1:

boolis_odd(intn){returnn%2==1;}

But in a language where modulo has the sign of the dividend, that is incorrect, because when n (the dividend) is negative and odd, n mod 2 returns −1, and the function returns false.

One correct alternative is to test that the remainder is not 0 (because remainder 0 is the same regardless of the signs):

boolis_odd(intn){returnn%2!=0;}

Another alternative is to use the fact that for any odd number, the remainder may be either 1 or −1:

boolis_odd(intn){returnn%2==1||n%2==-1;}

A simpler alternative is to treat the result of n % 2 as if it is a boolean value, where any non-zero value is true:

boolis_odd(intn){returnn%2;}

Performance issues

Modulo operations might be implemented such that a division with a remainder is calculated each time. For special cases, on some hardware, faster alternatives exist. For example, the modulo of powers of 2 can alternatively be expressed as a bitwise AND operation (assuming x is a positive integer, or using a non-truncating definition):

x % 2n == x & (2n - 1)

Examples:

x % 2 == x & 1
x % 4 == x & 3
x % 8 == x & 7

In devices and software that implement bitwise operations more efficiently than modulo, these alternative forms can result in faster calculations. [7]

Compiler optimizations may recognize expressions of the form expression % constant where constant is a power of two and automatically implement them as expression & (constant-1), allowing the programmer to write clearer code without compromising performance. This simple optimization is not possible for languages in which the result of the modulo operation has the sign of the dividend (including C), unless the dividend is of an unsigned integer type. This is because, if the dividend is negative, the modulo will be negative, whereas expression & (constant-1) will always be positive. For these languages, the equivalence x % 2n == x < 0 ? x | ~(2n - 1) : x & (2n - 1) has to be used instead, expressed using bitwise OR, NOT and AND operations.

Optimizations for general constant-modulus operations also exist by calculating the division first using the constant-divisor optimization.

Properties (identities)

Some modulo operations can be factored or expanded similarly to other mathematical operations. This may be useful in cryptography proofs, such as the Diffie–Hellman key exchange. Some of these properties[ which? ] require that a and n are integers.

In programming languages

Modulo operators in various programming languages
Language OperatorIntegerFloating-point Definition
ABAP MODYesYesEuclidean
ActionScript %YesNoTruncated
Ada modYesNoFloored [8]
remYesNoTruncated [8]
ALGOL 68 ÷×, modYesNoEuclidean
AMPL modYesNoTruncated
APL | [lower-alpha 2] YesYesFloored
AppleScript modYesNoTruncated
AutoLISP (rem d n)YesNoTruncated
AWK %YesNoTruncated
bash %YesNoTruncated
BASIC ModYesNoVaries by implementation
bc %YesNoTruncated
C
C++
%, divYesNoTruncated [lower-alpha 3]
fmod (C)
std::fmod (C++)
NoYesTruncated [11]
remainder (C)
std::remainder (C++)
NoYesRounded
C# %YesYesTruncated
Math.IEEERemainderNoYesRounded [12]
Clarion %YesNoTruncated
Clean remYesNoTruncated
Clojure modYesNoFloored [13]
remYesNoTruncated [14]
COBOL FUNCTION MODYesNoFloored [15]
FUNCTION REMYesYesTruncated [15]
CoffeeScript %YesNoTruncated
%%YesNoFloored [16]
ColdFusion %, MODYesNoTruncated
Common Intermediate Language rem (signed)YesYesTruncated [17]
rem.un (unsigned)YesNo
Common Lisp modYesYesFloored
remYesYesTruncated
Crystal %, moduloYesYesFloored
remainderYesYesTruncated
D %YesYesTruncated [18]
Dart %YesYesEuclidean [19]
remainder()YesYesTruncated [20]
Eiffel \\YesNoTruncated
Elixir rem/2YesNoTruncated [21]
Integer.mod/2YesNoFloored [22]
Elm modByYesNoFloored [23]
remainderByYesNoTruncated [24]
Erlang remYesNoTruncated
math:fmod/2NoYesTruncated (same as C) [25]
Euphoria modYesNoFloored
remainderYesNoTruncated
F# %YesYesTruncated
Math.IEEERemainderNoYesRounded [12]
Factor modYesNoTruncated
FileMaker ModYesNoFloored
Forth modYesNoImplementation defined
fm/modYesNoFloored
sm/remYesNoTruncated
Fortran modYesYesTruncated
moduloYesYesFloored
Frink modYesNoFloored
Full BASIC MODYesYesFloored [26]
REMAINDERYesYesTruncated [27]
GLSL %YesNoUndefined [28]
modNoYesFloored [29]
GameMaker Studio (GML)mod, %YesNoTruncated
GDScript (Godot) %YesNoTruncated
fmodNoYesTruncated
posmodYesNoEuclidean
fposmodNoYesEuclidean
Go %YesNoTruncated [30]
math.ModNoYesTruncated [31]
big.Int.ModYesNoEuclidean [32]
big.Int.RemYesNoTruncated [33]
Groovy %YesNoTruncated
Haskell modYesNoFloored [34]
remYesNoTruncated [34]
Data.Fixed.mod' (GHC)NoYesFloored
Haxe %YesNoTruncated
HLSL %YesYesUndefined [35]
J | [lower-alpha 2] YesNoFloored
Java %YesYesTruncated
Math.floorModYesNoFloored
JavaScript
TypeScript
%YesYesTruncated
Julia modYesYesFloored [36]
%, remYesYesTruncated [37]
Kotlin %, remYesYesTruncated [38]
modYesYesFloored [39]
ksh %YesNoTruncated (same as POSIX sh)
fmodNoYesTruncated
LabVIEW modYesYesTruncated
LibreOffice =MOD()YesNoFloored
Logo MODULOYesNoFloored
REMAINDERYesNoTruncated
Lua 5%YesYesFloored
Lua 4mod(x,y)YesYesTruncated
Liberty BASIC MODYesNoTruncated
Mathcad mod(x,y)YesNoFloored
Maple e mod m (by default), modp(e, m)YesNoEuclidean
mods(e, m)YesNoRounded
frem(e, m)YesYesRounded
Mathematica Mod[a, b]YesNoFloored
MATLAB modYesNoFloored
remYesNoTruncated
Maxima modYesNoFloored
remainderYesNoTruncated
Maya Embedded Language %YesNoTruncated
Microsoft Excel =MOD()YesYesFloored
Minitab MODYesNoFloored
Modula-2 MODYesNoFloored
REMYesNoTruncated
MUMPS #YesNoFloored
Netwide Assembler (NASM, NASMX)%, div (unsigned)YesNo
%% (signed)YesNoImplementation-defined [40]
Nim modYesNoTruncated
Oberon MODYesNoFloored-like [lower-alpha 4]
Objective-C %YesNoTruncated (same as C99)
Object Pascal, Delphi modYesNoTruncated
OCaml modYesNoTruncated [41]
mod_floatNoYesTruncated [42]
Occam \YesNoTruncated
Pascal (ISO-7185 and -10206)modYesNoEuclidean-like [lower-alpha 5]
Perl %YesNoFloored [lower-alpha 6]
POSIX::fmodNoYesTruncated
Phix modYesNoFloored
remainderYesNoTruncated
PHP %YesNoTruncated [44]
fmodNoYesTruncated [45]
PIC BASIC Pro\\YesNoTruncated
PL/I modYesNoFloored (ANSI PL/I)
PowerShell %YesNoTruncated
Programming Code (PRC)MATH.OP - 'MOD; (\)'YesNoUndefined
Progress moduloYesNoTruncated
Prolog (ISO 1995)modYesNoFloored
remYesNoTruncated
PureBasic %, Mod(x,y)YesNoTruncated
PureScript `mod`YesNoEuclidean [46]
Pure Data %YesNoTruncated (same as C)
modYesNoFloored
Python %YesYesFloored
math.fmodNoYesTruncated
Q# %YesNoTruncated [47]
R %%YesYesFloored [48]
Racket moduloYesNoFloored
remainderYesNoTruncated
Raku %NoYesFloored
RealBasic MODYesNoTruncated
Reason modYesNoTruncated
Rexx //YesYesTruncated
RPG %REMYesNoTruncated
Ruby %, modulo()YesYesFloored
remainder()YesYesTruncated
Rust %YesYesTruncated
rem_euclid()YesYesEuclidean [49]
SAS MODYesNoTruncated
Scala %YesYesTruncated
Scheme moduloYesNoFloored
remainderYesNoTruncated
Scheme R6RS modYesNoEuclidean [50]
mod0YesNoRounded [50]
flmodNoYesEuclidean
flmod0NoYesRounded
Scratch modYesYesFloored
Seed7 modYesYesFloored
remYesYesTruncated
SenseTalk moduloYesNoFloored
remYesNoTruncated
sh (POSIX) (includes bash, mksh, &c.)%YesNoTruncated (same as C) [51]
Smalltalk \\YesNoFloored
rem:YesNoTruncated
Snap! modYesNoFloored
Spin //YesNoFloored
Solidity %YesNoFloored
SQL (SQL:1999)mod(x,y)YesNoTruncated
SQL (SQL:2011)%YesNoTruncated
Standard ML modYesNoFloored
Int.remYesNoTruncated
Real.remNoYesTruncated
Stata mod(x,y)YesNoEuclidean
Swift %YesNoTruncated [52]
remainder(dividingBy:)NoYesRounded [53]
truncatingRemainder(dividingBy:)NoYesTruncated [54]
Tcl %YesNoFloored
fmod()NoYesTruncated (as C)
tcsh %YesNoTruncated
Torque %YesNoTruncated
Turing modYesNoFloored
Verilog (2001)%YesNoTruncated
VHDL modYesNoFloored
remYesNoTruncated
VimL %YesNoTruncated
Visual Basic ModYesNoTruncated
WebAssembly i32.rem_u, i64.rem_u (unsigned)YesNo [55]
i32.rem_s, i64.rem_s (signed)YesNoTruncated [55]
x86 assembly IDIVYesNoTruncated
XBase++ %YesYesTruncated
Mod()YesYesFloored
Zig %,

@mod, @rem

YesYesTruncated [56]
Z3 theorem prover div, modYesNoEuclidean

In addition, many computer systems provide a divmod functionality, which produces the quotient and the remainder at the same time. Examples include the x86 architecture's IDIV instruction, the C programming language's div() function, and Python's divmod() function.

Generalizations

Modulo with offset

Sometimes it is useful for the result of a modulo n to lie not between 0 and n − 1, but between some number d and d + n − 1. In that case, d is called an offset and d = 1 is particularly common.

There does not seem to be a standard notation for this operation, so let us tentatively use a moddn. We thus have the following definition: [57] x = a moddn just in case dxd + n − 1 and x mod n = a mod n. Clearly, the usual modulo operation corresponds to zero offset: a mod n = a mod0n.

The operation of modulo with offset is related to the floor function as follows:

To see this, let . We first show that x mod n = a mod n. It is in general true that (a + bn) mod n = a mod n for all integers b; thus, this is true also in the particular case when ; but that means that , which is what we wanted to prove. It remains to be shown that dxd + n − 1. Let k and r be the integers such that ad = kn + r with 0 ≤ rn − 1 (see Euclidean division). Then , thus . Now take 0 ≤ rn − 1 and add d to both sides, obtaining dd + rd + n − 1. But we've seen that x = d + r, so we are done.

The modulo with offset a moddn is implemented in Mathematica as Mod[a, n, d]. [57]

Implementing other modulo definitions using truncation

Despite the mathematical elegance of Knuth's floored division and Euclidean division, it is generally much more common to find a truncated division-based modulo in programming languages. Leijen provides the following algorithms for calculating the two divisions given a truncated integer division: [5]

/* Euclidean and Floored divmod, in the style of C's ldiv() */typedefstruct{/* This structure is part of the C stdlib.h, but is reproduced here for clarity */longintquot;longintrem;}ldiv_t;/* Euclidean division */inlineldiv_tldivE(longnumer,longdenom){/* The C99 and C++11 languages define both of these as truncating. */longq=numer/denom;longr=numer%denom;if(r<0){if(denom>0){q=q-1;r=r+denom;}else{q=q+1;r=r-denom;}}return(ldiv_t){.quot=q,.rem=r};}/* Floored division */inlineldiv_tldivF(longnumer,longdenom){longq=numer/denom;longr=numer%denom;if((r>0&&denom<0)||(r<0&&denom>0)){q=q-1;r=r+denom;}return(ldiv_t){.quot=q,.rem=r};}

For both cases, the remainder can be calculated independently of the quotient, but not vice versa. The operations are combined here to save screen space, as the logical branches are the same.

See also

Notes

  1. Mathematically, these two choices are but two of the infinite number of choices available for the inequality satisfied by a remainder.
  2. 1 2 Argument order reverses, i.e., α|ω computes , the remainder when dividing ω by α.
  3. C99 and C++11 define the behavior of % to be truncated. [9] The standards before then leave the behavior implementation-defined. [10]
  4. Divisor must be positive, otherwise undefined.
  5. As discussed by Boute, ISO Pascal's definitions of div and mod do not obey the Division Identity of D = d · (D / d) + D % d, and are thus fundamentally broken.
  6. Perl usually uses arithmetic modulo operator that is machine-independent. For examples and exceptions, see the Perl documentation on multiplicative operators. [43]

Related Research Articles

<span class="mw-page-title-main">Chinese remainder theorem</span> Theorem for solving simultaneous congruences

In mathematics, the Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.

In mathematics and computer programming, exponentiating by squaring is a general method for fast computation of large positive integer powers of a number, or more generally of an element of a semigroup, like a polynomial or a square matrix. Some variants are commonly referred to as square-and-multiply algorithms or binary exponentiation. These can be of quite general use, for example in modular arithmetic or powering of matrices. For semigroups for which additive notation is commonly used, like elliptic curves used in cryptography, this method is also referred to as double-and-add.

<span class="mw-page-title-main">Euclidean algorithm</span> Algorithm for computing greatest common divisors

In mathematics, the Euclidean algorithm, or Euclid's algorithm, is an efficient method for computing the greatest common divisor (GCD) of two integers (numbers), the largest number that divides them both without a remainder. It is named after the ancient Greek mathematician Euclid, who first described it in his Elements . It is an example of an algorithm, a step-by-step procedure for performing a calculation according to well-defined rules, and is one of the oldest algorithms in common use. It can be used to reduce fractions to their simplest form, and is a part of many other number-theoretic and cryptographic calculations.

In mathematics, the greatest common divisor (GCD) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers x, y, the greatest common divisor of x and y is denoted . For example, the GCD of 8 and 12 is 4, that is, gcd(8, 12) = 4.

<span class="mw-page-title-main">Modular arithmetic</span> Computation modulo a fixed integer

In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" when reaching a certain value, called the modulus. The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his book Disquisitiones Arithmeticae, published in 1801.

<span class="mw-page-title-main">Gaussian integer</span> Complex number whose real and imaginary parts are both integers

In number theory, a Gaussian integer is a complex number whose real and imaginary parts are both integers. The Gaussian integers, with ordinary addition and multiplication of complex numbers, form an integral domain, usually written as or

<span class="mw-page-title-main">Division (mathematics)</span> Arithmetic operation

Division is one of the four basic operations of arithmetic. The other operations are addition, subtraction, and multiplication. What is being divided is called the dividend, which is divided by the divisor, and the result is called the quotient.

<span class="mw-page-title-main">Floor and ceiling functions</span> Nearest integers from a number

In mathematics, the floor function (or greatest integer function) is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x, denoted x or floor(x). Similarly, the ceiling function maps x to the smallest integer greater than or equal to x, denoted x or ceil(x).

In arithmetic and computer programming, the extended Euclidean algorithm is an extension to the Euclidean algorithm, and computes, in addition to the greatest common divisor (gcd) of integers a and b, also the coefficients of Bézout's identity, which are integers x and y such that

Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s. Alphabets following a geometric distribution will have a Golomb code as an optimal prefix code, making Golomb coding highly suitable for situations in which the occurrence of small values in the input stream is significantly more likely than large values.

<span class="mw-page-title-main">Quotient</span> Mathematical result of division

In arithmetic, a quotient is a quantity produced by the division of two numbers. The quotient has widespread use throughout mathematics. It has two definitions: either the integer part of a division or a fraction or ratio. For example, when dividing 20 by 3, the quotient is 6 in the first sense and in the second sense.

In mathematics, the remainder is the amount "left over" after performing some computation. In arithmetic, the remainder is the integer "left over" after dividing one integer by another to produce an integer quotient. In algebra of polynomials, the remainder is the polynomial "left over" after dividing one polynomial by another. The modulo operation is the operation that produces such a remainder when given a dividend and divisor.

<span class="mw-page-title-main">Euclidean division</span> Division with remainder of integers

In arithmetic, Euclidean division – or division with remainder – is the process of dividing one integer by another, in a way that produces an integer quotient and a natural number remainder strictly smaller than the absolute value of the divisor. A fundamental property is that the quotient and the remainder exist and are unique, under some conditions. Because of this uniqueness, Euclidean division is often considered without referring to any method of computation, and without explicitly computing the quotient and the remainder. The methods of computation are called integer division algorithms, the best known of which being long division.

In modular arithmetic computation, Montgomery modular multiplication, more commonly referred to as Montgomery multiplication, is a method for performing fast modular multiplication. It was introduced in 1985 by the American mathematician Peter L. Montgomery.

Zeller's congruence is an algorithm devised by Christian Zeller in the 19th century to calculate the day of the week for any Julian or Gregorian calendar date. It can be considered to be based on the conversion between Julian day and the calendar date.

<span class="mw-page-title-main">Eisenstein integer</span> Complex number whose mapping on a coordinate plane produces a triangular lattice

In mathematics, the Eisenstein integers, occasionally also known as Eulerian integers, are the complex numbers of the form

A division algorithm is an algorithm which, given two integers N and D, computes their quotient and/or remainder, the result of Euclidean division. Some are applied by hand, while others are employed by digital circuit designs and software.

In algebra, the greatest common divisor of two polynomials is a polynomial, of the highest possible degree, that is a factor of both the two original polynomials. This concept is analogous to the greatest common divisor of two integers.

In number theory, the Fermat quotient of an integer a with respect to an odd prime p is defined as

In modular arithmetic, Barrett reduction is a reduction algorithm introduced in 1986 by P.D. Barrett.

References

  1. Weisstein, Eric W. "Congruence". Wolfram MathWorld. Retrieved 2020-08-27.
  2. Caldwell, Chris. "residue". Prime Glossary. Retrieved August 27, 2020.
  3. Knuth, Donald. E. (1972). The Art of Computer Programming . Addison-Wesley.
  4. Boute, Raymond T. (April 1992). "The Euclidean definition of the functions div and mod". ACM Transactions on Programming Languages and Systems. 14 (2). ACM Press (New York, NY, USA): 127–144. doi:10.1145/128861.128862. hdl: 1854/LU-314490 . S2CID   8321674.
  5. 1 2 Leijen, Daan (December 3, 2001). "Division and Modulus for Computer Scientists" (PDF). Retrieved 2014-12-25.
  6. Peterson, Doctor (5 July 2001). "Mod Function and Negative Numbers". Math Forum - Ask Dr. Math. Archived from the original on 2019-10-22. Retrieved 22 October 2019.
  7. Horvath, Adam (July 5, 2012). "Faster division and modulo operation - the power of two".
  8. 1 2 "ISO/IEC 8652:2012 - Information technology — Programming languages — Ada". ISO, IEC. 2012. sec. 4.5.5 Multiplying Operators.{{cite journal}}: Cite journal requires |journal= (help)
  9. "C99 specification (ISO/IEC 9899:TC2)" (PDF). 2005-05-06. sec. 6.5.5 Multiplicative operators. Retrieved 16 August 2018.
  10. "ISO/IEC 14882:2003: Programming languages – C++". International Organization for Standardization (ISO), International Electrotechnical Commission (IEC). 2003. sec. 5.6.4. the binary % operator yields the remainder from the division of the first expression by the second. .... If both operands are nonnegative then the remainder is nonnegative; if not, the sign of the remainder is implementation-defined{{cite journal}}: Cite journal requires |journal= (help)
  11. "ISO/IEC 9899:1990: Programming languages – C". ISO, IEC. 1990. sec. 7.5.6.4. The fmod function returns the value x - i * y, for some integer i such that, if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y.{{cite journal}}: Cite journal requires |journal= (help)
  12. 1 2 dotnet-bot. "Math.IEEERemainder(Double, Double) Method (System)". Microsoft Learn. Retrieved 2022-10-04.
  13. "clojure.core - Clojure v1.10.3 API documentation". clojure.github.io. Retrieved 2022-03-16.
  14. "clojure.core - Clojure v1.10.3 API documentation". clojure.github.io. Retrieved 2022-03-16.
  15. 1 2 ISO/IEC JTC 1/SC 22/WG 4 (January 2023). ISO/IEC 1989:2023 – Programming language COBOL . ISO.{{cite book}}: CS1 maint: numeric names: authors list (link)
  16. CoffeeScript operators
  17. ISO/IEC JTC 1/SC 22 (February 2012). ISO/IEC 23271:2012 — Information technology — Common Language Infrastructure (CLI). ISO. §§ III.3.55–56.{{cite book}}: CS1 maint: numeric names: authors list (link)
  18. "Expressions - D Programming Language". dlang.org. Retrieved 2021-06-01.
  19. "operator % method - num class - dart:core library - Dart API". api.dart.dev. Retrieved 2021-06-01.
  20. "remainder method - num class - dart:core library - Dart API". api.dart.dev. Retrieved 2021-06-01.
  21. "Kernel — Elixir v1.11.3". hexdocs.pm. Retrieved 2021-01-28.
  22. "Integer — Elixir v1.11.3". hexdocs.pm. Retrieved 2021-01-28.
  23. "Basics - core 1.0.5". package.elm-lang.org. Retrieved 2022-03-16.
  24. "Basics - core 1.0.5". package.elm-lang.org. Retrieved 2022-03-16.
  25. "Erlang -- math". erlang.org. Retrieved 2021-06-01.
  26. ANSI (28 January 1987). Programming Languages — Full BASIC. New York: American National Standards Institute. § 5.4.4. X modulo Y, i.e., X-Y*INT(X/Y).
  27. ANSI (28 January 1987). Programming Languages — Full BASIC. New York: American National Standards Institute. § 5.4.4. The remainder function, i.e., X-Y*IP(X/Y).
  28. "GLSL Language Specification, Version 4.50.7" (PDF). section 5.9 Expressions. If both operands are non-negative, then the remainder is non-negative. Results are undefined if one or both operands are negative.
  29. "GLSL Language Specification, Version 4.50.7" (PDF). section 8.3 Common Functions.
  30. "The Go Programming Language Specification - The Go Programming Language". go.dev. Retrieved 2022-02-28.
  31. "math package - math - pkg.go.dev". pkg.go.dev. Retrieved 2022-02-28.
  32. "big package - math/big - pkg.go.dev". pkg.go.dev. Retrieved 2022-02-28.
  33. "big package - math/big - pkg.go.dev". pkg.go.dev. Retrieved 2024-04-12.
  34. 1 2 "6 Predefined Types and Classes". www.haskell.org. Retrieved 2022-05-22.
  35. "Operators". Microsoft . Retrieved 2021-07-19. The % operator is defined only in cases where either both sides are positive or both sides are negative. Unlike C, it also operates on floating-point data types, as well as integers.
  36. "Mathematics · The Julia Language". docs.julialang.org. Retrieved 2021-11-20.
  37. "Mathematics · The Julia Language". docs.julialang.org. Retrieved 2021-11-20.
  38. "rem - Kotlin Programming Language". Kotlin. Retrieved 2021-05-05.
  39. "mod - Kotlin Programming Language". Kotlin. Retrieved 2021-05-05.
  40. "Chapter 3: The NASM Language". NASM - The Netwide Assembler version 2.15.05.
  41. "OCaml library : Stdlib". ocaml.org. Retrieved 2022-02-19.
  42. "OCaml library : Stdlib". ocaml.org. Retrieved 2022-02-19.
  43. Perl documentation
  44. "PHP: Arithmetic Operators - Manual". www.php.net. Retrieved 2021-11-20.
  45. "PHP: fmod - Manual". www.php.net. Retrieved 2021-11-20.
  46. "EuclideanRing".
  47. QuantumWriter. "Expressions". docs.microsoft.com. Retrieved 2018-07-11.
  48. "R: Arithmetic Operators". search.r-project.org. Retrieved 2022-12-24.
  49. "F32 - Rust".
  50. 1 2 r6rs.org
  51. "Shell Command Language". pubs.opengroup.org. Retrieved 2021-02-05.
  52. "Apple Developer Documentation". developer.apple.com. Retrieved 2021-11-20.
  53. "Apple Developer Documentation". developer.apple.com. Retrieved 2021-11-20.
  54. "Apple Developer Documentation". developer.apple.com. Retrieved 2021-11-20.
  55. 1 2 Rossberg, Andreas, ed. (19 April 2022). "WebAssembly Core Specification: Version 2.0". World Wide Web Consortium. § 4.3.2 Integer Operations.
  56. "Zig Documentation". Zig Programming Language. Retrieved 2022-12-18.
  57. 1 2 "Mod". Wolfram Language & System Documentation Center. Wolfram Research. 2020. Retrieved April 8, 2020.