GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Main page
  • Contents
  • Current events
  • Random article
  • About Wikipedia
  • Contact us
  • Help
  • Learn to edit
  • Community portal
  • Recent changes
  • Upload file
  • Special pages
  • Search
  • Donate

This view

  • Original page
  • New address

GeezerVison is showing en.wikipedia.org — Modulo - Wikipedia

(Redirected from Modulo operation)
This article is about the binary operation a mod m. For the (mod m) notation, see Modular arithmetic. For other uses, see Modulo (disambiguation).

In mathematics and computing, modulo is the binary operation of which the value is the remainder or signed remainder of a division of one number by another, the latter being called the modulus of the operation.

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

For example, 5mod2=1, because dividing 5 by 2 yields a remainder of 1 (besides the quotient of 2), while 9mod3=0, because 3 divides evenly into 9, thus leaving a remainder of 0.

In computing, although the modulo operation is typically applied with both of its arguments, a and m, being integers, many systems now allow other types of numeric operands. When they are both integers, the range of values for amodm is from 0 to m−1, inclusive. The value of amod1 is always 0, for any integer a. When exactly one of a or m is negative, the basic definition breaks down, and programming languages differ in how these values are defined.

Variants of the definition

In mathematics, the value of an expression amodm is, technically, 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] For example, 11mod3 equals not 2 (the least positive residue), but the entire set {...,−4,−1,2,5,8,11,14,...} of all integers that are congruent to 2 modulo 3 (which is to say those integers that are 2 more than a multiple of 3). This equivalence class would typically be denoted by [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≠0 satisfy the following conditions:

q∈ℤa=nq+r(n≠0)|r|<|n| 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.[a] 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). Some systems leave a modulo 0 undefined, though others define it as a.

  •   Quotient (q) and   remainder (r) as functions of dividend (a), using truncated division

    Many implementations use truncated division, for which the quotient is defined by q=trunc⁡(an) where trunc is the integral part function (rounding toward zero), i.e. the truncation to zero significant digits. Thus according to equation (1), the remainder has the same sign as the dividend a so can take 2|n| − 1 values: r=a−ntrunc⁡(an)

  • Quotient and remainder using floored division

    Donald Knuth[3] promotes floored division, for which the quotient is defined by q=⌊an⌋ where ⌊⌋ is the floor function (rounding down). Thus according to equation (1), the remainder has the same sign as the divisor n: r=a−n⌊an⌋

  • Quotient and remainder using Euclidean division

    Raymond T. Boute[4] promotes Euclidean division, for which the non-negative remainder r∈{0,1,2...} is defined by r:=a−nq such that 0≤r<|n|. (Emphasis added.) Under this definition, we can say the following about the quotient q: q=a−rn∈ℤ=sgn(n)⋅a−r|n|=sgn(n)⋅(a|n|−r|n|)=sgn(n)⋅⌊a|n|⌋ where sgn is the sign function, ⌊⌋ is the floor function (rounding down), and a|n|∈ℚ, r|n|∈ℚ are rational numbers.

    Equivalently, one may instead define the quotient q∈ℤ as follows: q:=sgn⁡(n)⌊a|n|⌋={⌊an⌋if n>0⌈an⌉if n<0 where ⌈⌉ is the ceiling function (rounding up). Thus according to equation (1), the remainder r is non-negative: r=a−nq=a−|n|⌊a|n|⌋

  • Quotient and remainder using rounded division

    Common Lisp and IEEE 754 use rounded division, for which the quotient is defined by q=round⁡(an) where round is the round function (rounding half to even). Thus according to equation (1), the remainder falls between −n2 and n2, and its sign depends on which side of zero it falls to be within these boundaries: r=a−nround⁡(an)

  • Quotient and remainder using ceiling division

    Common Lisp also uses ceiling division, for which the quotient is defined by q=⌈an⌉ where ⌈⌉ is the ceiling function (rounding up). Thus according to equation (1), the remainder has the opposite sign of that of the divisor: r=a−n⌈an⌉

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.

However, truncated division satisfies the identity (−a)/b=−(a/b)=a/(−b).[5][6]

Notation

This section is about the binary mod operation. For the (mod m) notation, see congruence relation.

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:

bool is_odd(int n) {
    return n % 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):

bool is_odd(int n) {
    return n % 2 != 0;
}

Or with the binary arithmetic:

bool is_odd(int n) {
    return n & 1;
}

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)

See also: Modular arithmetic § Properties

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. The properties involving multiplication, division, and exponentiation generally require that a and n are integers.

  • Identity:
    • (a mod n) mod n = a mod n.
    • nx mod n = 0 for all positive integer values of x.
    • If p is a prime number which is not a divisor of b, then abp−1 mod p = a mod p, due to Fermat's little theorem.
  • Inverse:
    • [(−a mod n) + (a mod n)] mod n = 0.
    • b−1 mod n denotes the modular multiplicative inverse, which is defined if and only if b and n are relatively prime, which is the case when the left hand side is defined: [(b−1 mod n)(b mod n)] mod n = 1.
  • Distributive:
    • (a + b) mod n = [(a mod n) + (b mod n)] mod n.
    • ab mod n = [(a mod n)(b mod n)] mod n.
  • Division (definition): ⁠a/b⁠ mod n = [(a mod n)(b−1 mod n)] mod n, when the right hand side is defined (that is when b and n are coprime), and undefined otherwise.
  • Inverse multiplication: [(ab mod n)(b−1 mod n)] mod n = a mod n.

Diophantine definition

For non-negative integers a, n and r, r = a mod n holds if and only if there are non-negative integers q and s with a=nq+randr+s+1=n, since the second equation expresses r<n. The two equations can be combined into the single Diophantine equation (a−nq−r)2+(r+s+1−n)2=0, so the graph of the modulo operation on the non-negative integers is a Diophantine set. The same equation determines the quotient q, so the graph of divmod is Diophantine as well. The equation has no solution for n = 0, in line with leaving a modulo 0 undefined. Since the modulo operation is computable, its graph being Diophantine also follows from the MRDP theorem.

In programming languages

Modulo operators in various programming languages
Language Operator Integer Floating-point Definition
ABAP MOD Yes Yes Euclidean[8]
ActionScript % Yes Yes Truncated[9]
Ada mod Yes No Floored[10]
rem Yes No Truncated[10]
ALGOL 68 ÷×, ÷*, %×, %*, mod[b] Yes No Euclidean[11]
AMPL mod Yes No Truncated
APL |[c] Yes Yes Floored
AppleScript mod Yes Yes Truncated
AutoLISP rem Yes Yes Truncated
AWK % Yes Yes Truncated (same as fmod in C)[12]
BASIC Mod Yes No Varies by implementation
bc % Yes Yes Truncated[13]
C
C++
%, div Yes No Truncated[d]
fmod (C)
std::fmod (C++)
No Yes Truncated[16]
remainder (C)
std::remainder (C++)
No Yes Rounded[17]
C# % Yes Yes Truncated[18]
Math.IEEERemainder No Yes Rounded[19]
Clarion % Yes No Truncated
Clean rem Yes No Truncated
Clojure mod Yes No Floored[20]
rem Yes No Truncated[21]
COBOL FUNCTION MOD Yes No Floored[22]
FUNCTION REM Yes Yes Truncated[22]
CoffeeScript % Yes No Truncated (same as JavaScript)[23]
%% Yes No Floored[23]
ColdFusion %, MOD Yes No Truncated
Common Intermediate Language rem (signed) Yes Yes Truncated[24]
rem.un (unsigned) Yes No —N/a
Common Lisp mod Yes Yes Floored[25]
rem Yes Yes Truncated[25]
Crystal %, modulo Yes Yes Floored
remainder Yes Yes Truncated
CSS mod() Yes Yes Floored[26]
rem() Yes Yes Truncated[27]
D % Yes Yes Truncated[28]
Dart % Yes Yes Euclidean[29]
remainder() Yes Yes Truncated[30]
dc % Yes Yes Truncated[31]
Eiffel \\ Yes No Truncated
Elixir rem/2 Yes No Truncated[32]
Integer.mod/2 Yes No Floored[33]
Elm modBy Yes No Floored[34]
remainderBy Yes No Truncated[35]
Erlang rem Yes No Truncated
math:fmod/2 No Yes Truncated (same as C)[36]
Euphoria remainder Yes Yes Truncated[37]
mod Yes Yes Floored[38]
F# % Yes Yes Truncated (same as C#)[39]
Math.IEEERemainder No Yes Rounded[19]
Factor mod Yes Yes Truncated[40]
rem Yes Yes Euclidean[41]
FileMaker Mod Yes No Floored
Forth mod Yes No Implementation defined
fm/mod Yes No Floored
sm/rem Yes No Truncated
Fortran mod Yes Yes Truncated[42]
modulo Yes Yes Floored[43]
Frink %, mod Yes Yes Floored[44]
Full BASIC MOD Yes Yes Floored[45]
REMAINDER Yes Yes Truncated[46]
GLSL % Yes No Undefined[47]
mod No Yes Floored[48]
GameMaker Studio (GML) mod, % Yes No Truncated
GDScript (Godot) % Yes No Truncated[49]
posmod Yes No Euclidean[50]
fmod No Yes Truncated[51]
fposmod No Yes Euclidean[52]
Go % Yes No Truncated[53]
math.Mod No Yes Truncated[54]
big.Int.Mod Yes No Euclidean[55]
big.Int.Rem Yes No Truncated[56]
Groovy % Yes No Truncated
Haskell mod Yes No Floored[57]
rem Yes No Truncated[57]
Data.Fixed.mod' (GHC) No Yes Floored
Haxe % Yes Yes Truncated[58]
HLSL % Yes Yes Undefined[59]
J |[c] Yes No Floored
Java % Yes Yes Truncated[60]
Integer.remainderUnsigned, Long.remainderUnsigned Yes No —N/a[61][62]
Math.ceilMod, StrictMath.ceilMod Yes No Ceiling[63][64][65][66][67][68]
Math.floorMod, StrictMath.floorMod Yes No Floored[69][70][71][72][73][74]
Math.IEEEremainder, StrictMath.IEEEremainder No Yes Rounded[75][76]
a.mod(b) (BigInteger) Yes No Euclidean[77]
a.remainder(b) (BigInteger) Yes No Truncated[78]
a.remainder(b), a.remainder(b, mathContext) (BigDecimal) No Yes Truncated[79][80]
JavaScript
TypeScript
% Yes Yes Truncated
Julia mod Yes Yes Floored[81]
%, rem Yes Yes Truncated[82]
Kotlin %, rem Yes Yes Truncated[83]
mod Yes Yes Floored[84]
ksh % Yes No Truncated (same as POSIX sh)
fmod No Yes Truncated
LabVIEW mod Yes Yes Truncated
LibreOffice MOD Yes Yes Floored[85]
Logo MODULO Yes No Floored
REMAINDER Yes No Truncated
Lua 5 % Yes Yes Floored
Lua 4 mod(x,y) Yes Yes Truncated
Liberty BASIC MOD Yes No Truncated
Mathcad mod(x,y) Yes No Floored
Maple e mod m (by default), modp(e, m) Yes No Euclidean
mods(e, m) Yes No Rounded
frem(e, m) Yes Yes Rounded
Mathematica Mod[a, b] Yes Yes Floored[86]
MATLAB mod Yes Yes Floored[87]
rem Yes Yes Truncated[88]
Maxima mod Yes No Floored
remainder Yes No Truncated
Maya Embedded Language % Yes No Truncated
fmod No Yes Truncated (same as C)[89]
Microsoft Excel MOD Yes Yes Floored[90]
Minitab MOD Yes No Floored
Modula-2 MOD Yes No Floored
REM Yes No Truncated
MUMPS # Yes No Floored[91]
Netwide Assembler (NASM, NASMX) %, div (unsigned) Yes No —N/a
%% (signed) Yes No Implementation-defined[92]
Nim mod Yes Yes Truncated[93][94]
floorMod Yes Yes Floored[95]
Oberon MOD Yes No Floored-like[e]
Objective-C % Yes No Truncated (same as C99)
Object Pascal, Delphi mod Yes No Truncated
OCaml mod, Int.rem Yes No Truncated[96][97]
mod_float, Float.rem No Yes Truncated[98][99]
Occam \ Yes No Truncated
Pascal (ISO-7185 and -10206) mod Yes No Euclidean-like[f]
Perl % Yes No Floored[g]
POSIX::fmod No Yes Truncated (same as C)[101]
PHP % Yes No Truncated[102]
fmod No Yes Truncated[103]
PIC BASIC Pro \\ Yes No Truncated
PL/I mod Yes No Floored (ANSI PL/I)
PowerShell % Yes No Truncated
Programming Code (PRC) MATH.OP - 'MOD; (\)' Yes No Undefined
Progress modulo Yes No Truncated
Prolog mod Yes No Floored
rem Yes No Truncated
PureBasic % Yes No Truncated
Mod(x,y) No Yes Truncated[104]
PureScript `mod` Yes No Euclidean[105]
Pure Data % Yes No Truncated (same as C)
mod Yes No Floored
Python % Yes Yes Floored[106]
math.fmod No Yes Truncated[107]
math.remainder No Yes Rounded[108]
Q# % Yes No Truncated[109]
R %% Yes Yes Floored[110]
Racket modulo Yes Some[h] Floored[112]
remainder Yes Some[h] Truncated[113]
Raku % No Yes Floored
Reason mod Yes No Truncated
Rexx // Yes Yes Truncated
RPG %REM Yes No Truncated
Ruby %, modulo() Yes Yes Floored
remainder() Yes Yes Truncated
Rust % Yes Yes Truncated[114]
rem_euclid() Yes Yes Euclidean[115]
SAS MOD Yes No Truncated
Scala % Yes Yes Truncated
Scheme modulo Yes No Floored
remainder Yes No Truncated
Scheme R6RS mod Yes No Euclidean[116]
mod0 Yes No Rounded[116]
flmod No Yes Euclidean
flmod0 No Yes Rounded
Scratch mod Yes Yes Floored
Seed7 mod Yes Yes Floored
rem Yes Yes Truncated
SenseTalk modulo Yes No Floored
rem Yes No Truncated
sh (POSIX) (includes bash, mksh, &c.) % Yes No Truncated (same as C)[117]
Smalltalk \\ Yes Yes Floored[118]: sec. 5.6.2.9 
rem: Yes Yes Truncated[118]: sec. 5.6.2.30 
Snap! mod Yes No Floored
Spin // Yes No Floored
Solidity % Yes No Truncated[119]
SQL (SQL:1999) mod(x,y) Yes No Truncated
SQL (SQL:2011) % Yes No Truncated
Standard ML mod Yes No Floored
Int.rem Yes No Truncated
Real.rem No Yes Truncated
Stata mod(x,y) Yes No Euclidean
Swift % Yes No Truncated[120]
remainder(dividingBy:) No Yes Rounded[121]
truncatingRemainder(dividingBy:) No Yes Truncated[122]
Tcl expr a % n, ::tcl::mathop::% a n[i] Yes No Floored[124][125]
expr fmod(a, n), ::tcl::mathfunc::fmod a n[j] No Yes Truncated (same as C)
tcsh % Yes No Truncated
Torque % Yes No Truncated
Turing mod Yes No Floored
Verilog (2001) % Yes No Truncated
VHDL mod Yes No Floored
rem Yes No Truncated
VimL % Yes No Truncated
Visual Basic Mod Yes No Truncated
WebAssembly i32.rem_u, i64.rem_u (unsigned) Yes No —N/a[127]
i32.rem_s, i64.rem_s (signed) Yes No Truncated[127]
x86 assembly DIV (unsigned)YesNo—N/a
IDIV (signed)YesNoTruncated
FPREMNoYesTruncated
FPREM1NoYesRounded
XBase++ % Yes Yes Truncated
Mod() Yes Yes Floored
Xojo Mod Yes Partial[k] Truncated[128]
Zig %, @rem Yes Yes Truncated[129]
@mod Yes Yes Floored
Z3 Theorem Prover div, mod Yes No Euclidean

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 DIV and IDIV instructions, 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 modd n. We thus have the following definition:[130] x = a modd n just in case d ≤ x ≤ d + n − 1 and x mod n = a mod n. Clearly, the usual modulo operation corresponds to zero offset: a mod n = a mod0 n.

The operation of modulo with offset is related to the floor function as follows: amoddn=a−n⌊a−dn⌋.

To see this, let x=a−n⌊a−dn⌋. 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 b=−⌊a−dn⌋; but that means that xmodn=(a−n⌊a−dn⌋)modn=amodn, which is what we wanted to prove. It remains to be shown that d ≤ x ≤ d + n − 1. Let k and r be the integers such that a − d = kn + r with 0 ≤ r ≤ n − 1 (see Euclidean division). Then ⌊a−dn⌋=k, thus x=a−n⌊a−dn⌋=a−nk=d+r. Now take 0 ≤ r ≤ n − 1 and add d to both sides, obtaining d ≤ d + r ≤ d + n − 1. But we've seen that x = d + r, so we are done.

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

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:

/* Euclidean and Floored divmod, in the style of C's ldiv() */
typedef struct {
  /* This structure is part of the C stdlib.h, but is reproduced here for clarity */
  long int quot;
  long int rem;
} ldiv_t;

/* Euclidean division */
inline ldiv_t ldivE(long numer, long denom) {
  /* The C99 and C++11 languages define both of these as truncating. */
  long q = numer / denom;
  long r = 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 */
inline ldiv_t ldivF(long numer, long denom) {
  long q = numer / denom;
  long r = 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

  • Modulo (disambiguation) – many uses of the word modulo, all of which grew out of Carl F. Gauss' approach to modular arithmetic in 1801.
  • Modulo (mathematics), general use of the term in mathematics
  • Modular exponentiation
  • Turn (angle)

Notes

  1. ↑ Mathematically, these two choices are but two of the infinite number of choices available for the inequality satisfied by a remainder.
  2. ↑ The revised report uses boldface to distinguish between keywords and identifiers, but permits other formats, including capitalization (e.g. MOD).
  3. 1 2 Argument order reverses, i.e., α|ω computes ωmodα, the remainder when dividing ω by α.
  4. ↑ C99 and C++11 define the behavior of % to be truncated.[14] The standards before then leave the behavior implementation-defined.[15]
  5. ↑ Divisor must be positive, otherwise undefined.
  6. ↑ 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.
  7. ↑ Perl usually uses arithmetic modulo operator that is machine-independent. For examples and exceptions, see the Perl documentation on multiplicative operators.[100]
  8. 1 2 Racket defines an integer as a rational number for which round produces the same number when applied. This includes some inexact numbers, like 42.0, but excludes others, like 3.14.[111]
  9. ↑ The expr command is defined independently of commands in the ::tcl::mathop namespace.[123]
  10. ↑ The expr command is defined in terms of commands in the ::tcl::mathfunc namespace.[126]
  11. ↑ Coerces floating-point operands to integers before calculating the result.

References

  1. ↑ Weisstein, Eric W. "Congruence". Wolfram MathWorld. Retrieved 27 August 2020.
  2. ↑ Caldwell, Chris. "residue". Prime Glossary. Retrieved 27 August 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. ↑ Peterson, Doctor (5 July 2001). "Mod Function and Negative Numbers". Math Forum - Ask Dr. Math. Archived from the original on 22 October 2019. Retrieved 22 October 2019.
  6. ↑ "Ada 83 LRM, Sec 4.5: Operators and Expression Evaluation". archive.adaic.com. Retrieved 3 March 2025.
  7. ↑ Horvath, Adam (5 July 2012). "Faster division and modulo operation - the power of two".
  8. ↑ "ABAP Keyword Documentation". help.sap.com. 2024. Retrieved 18 January 2026.
  9. ↑ "Operators - Adobe ActionScript® 3 (AS3) API Reference". help.adobe.com. Retrieved 19 January 2026.
  10. 1 2 ISO/IEC 8652:2012 - Information technology — Programming languages — Ada. ISO, IEC. 2012. sec. 4.5.5 Multiplying Operators.
  11. ↑ Revised Report on the Algorithmic Language Algol 68. IFIP WG2.1. 1973. sec. 10.2.3.3.n.
  12. ↑ "awk". pubs.opengroup.org. Retrieved 19 January 2026.
  13. ↑ "bc". pubs.opengroup.org. Retrieved 23 May 2026.
  14. ↑ "C99 specification (ISO/IEC 9899:TC2)" (PDF). 6 May 2005. sec. 6.5.5 Multiplicative operators. Retrieved 16 August 2018.
  15. ↑ 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
  16. ↑ 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.
  17. ↑ ISO/IEC 9899:1999: Programming languages — C. ISO, IEC. 1999. sec. 7.12.10.2. The remainder functions compute the remainder x REM y required by IEC 60559.
  18. ↑ "Expressions - C# language specification". learn.microsoft.com. Retrieved 19 January 2026.
  19. 1 2 dotnet-bot. "Math.IEEERemainder(Double, Double) Method (System)". Microsoft Learn. Retrieved 4 October 2022.
  20. ↑ "clojure.core - Clojure v1.10.3 API documentation". clojure.github.io. Retrieved 16 March 2022.
  21. ↑ "clojure.core - Clojure v1.10.3 API documentation". clojure.github.io. Retrieved 16 March 2022.
  22. 1 2 ISO/IEC JTC 1/SC 22/WG 4 (January 2023). ISO/IEC 1989:2023 – Programming language COBOL. ISO.
  23. 1 2 "CoffeeScript". coffeescript.org. Retrieved 22 July 2026.
  24. ↑ ISO/IEC JTC 1/SC 22 (February 2012). ISO/IEC 23271:2012 — Information technology — Common Language Infrastructure (CLI). ISO. §§ III.3.55–56.
  25. 1 2 "CLHS: Function MOD, REM". www.lispworks.com. Retrieved 20 January 2026.
  26. ↑ "mod() - CSS: Cascading Style Sheets | MDN". developer.mozilla.org. 22 June 2024. Retrieved 23 October 2024.
  27. ↑ "rem() - CSS: Cascading Style Sheets | MDN". developer.mozilla.org. 15 October 2024. Retrieved 23 October 2024.
  28. ↑ "Expressions - D Programming Language". dlang.org. Retrieved 1 June 2021.
  29. ↑ "operator % method - num class - dart:core library - Dart API". api.dart.dev. Retrieved 1 June 2021.
  30. ↑ "remainder method - num class - dart:core library - Dart API". api.dart.dev. Retrieved 1 June 2021.
  31. ↑ "dc, an arbitrary precision calculator". www.gnu.org. Archived from the original on 10 December 2025. Retrieved 23 May 2026.
  32. ↑ "Kernel — Elixir v1.11.3". hexdocs.pm. Retrieved 28 January 2021.
  33. ↑ "Integer — Elixir v1.11.3". hexdocs.pm. Retrieved 28 January 2021.
  34. ↑ "Basics - core 1.0.5". package.elm-lang.org. Retrieved 16 March 2022.
  35. ↑ "Basics - core 1.0.5". package.elm-lang.org. Retrieved 16 March 2022.
  36. ↑ "Erlang -- math". erlang.org. Retrieved 1 June 2021.
  37. ↑ "OpenEuphoria: Euphoria v4.0". openeuphoria.org. Retrieved 20 January 2026.
  38. ↑ "OpenEuphoria: Euphoria v4.0". openeuphoria.org. Retrieved 20 January 2026.
  39. ↑ "18. The F# Library FSharp.Core.dll - F# Language Specification". fsharp.github.io. Retrieved 19 January 2026.
  40. ↑ "mod ( x y -- z ) - Factor Documentation". docs.factorcode.org. Retrieved 21 January 2026.
  41. ↑ "rem ( x y -- z ) - Factor Documentation". docs.factorcode.org. Retrieved 21 January 2026.
  42. ↑ "Manipulation and properties of numeric values — Fortran Programming Language". fortran-lang.org. Retrieved 22 May 2026.
  43. ↑ "Manipulation and properties of numeric values — Fortran Programming Language". fortran-lang.org. Retrieved 22 May 2026.
  44. ↑ "Frink". frinklang.org. Retrieved 22 July 2026.
  45. ↑ 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).
  46. ↑ 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).
  47. ↑ "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.
  48. ↑ "GLSL Language Specification, Version 4.50.7" (PDF). section 8.3 Common Functions.
  49. ↑ "int". Godot Engine documentation. Retrieved 19 January 2026.
  50. ↑ "@GlobalScope". Godot Engine documentation. Retrieved 19 January 2026.
  51. ↑ "@GlobalScope". Godot Engine documentation. Retrieved 19 January 2026.
  52. ↑ "@GlobalScope". Godot Engine documentation. Retrieved 19 January 2026.
  53. ↑ "The Go Programming Language Specification - The Go Programming Language". go.dev. Retrieved 28 February 2022.
  54. ↑ "math package - math - pkg.go.dev". pkg.go.dev. Retrieved 28 February 2022.
  55. ↑ "big package - math/big - pkg.go.dev". pkg.go.dev. Retrieved 28 February 2022.
  56. ↑ "big package - math/big - pkg.go.dev". pkg.go.dev. Retrieved 12 April 2024.
  57. 1 2 "6 Predefined Types and Classes". www.haskell.org. Retrieved 22 May 2022.
  58. ↑ "Binary Operators". Haxe - The Cross-platform Toolkit. Retrieved 20 January 2026.
  59. ↑ "Operators". Microsoft. 30 June 2021. Retrieved 19 July 2021. 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.
  60. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 24 May 2026.
  61. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  62. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  63. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  64. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  65. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  66. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  67. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  68. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  69. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  70. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  71. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  72. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  73. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  74. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  75. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  76. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  77. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  78. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  79. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  80. ↑ "Java Platform, Standard Edition Java API Reference". docs.oracle.com. Retrieved 25 May 2026.
  81. ↑ "Mathematics · The Julia Language". docs.julialang.org. Retrieved 20 November 2021.
  82. ↑ "Mathematics – The Julia Language". docs.julialang.org. Retrieved 20 November 2021.
  83. ↑ "rem – Kotlin Programming Language". Kotlin. Retrieved 5 May 2021.
  84. ↑ "mod – Kotlin Programming Language". Kotlin. Retrieved 5 May 2021.
  85. ↑ "Mathematical Functions". help.libreoffice.org. Retrieved 21 January 2026.
  86. ↑ "Mod: Get the remainder on division—Wolfram Documentation". reference.wolfram.com. Retrieved 25 May 2026.
  87. ↑ "mod - Remainder after division (modulo operation) - MATLAB". www.mathworks.com. Archived from the original on 15 January 2026. Retrieved 21 January 2026.
  88. ↑ "rem - Remainder after division - MATLAB". www.mathworks.com. Archived from the original on 1 January 2026. Retrieved 21 January 2026.
  89. ↑ "fmod command". help.autodesk.com. Retrieved 14 June 2026.
  90. ↑ "MOD function - Microsoft Support". support.microsoft.com. Retrieved 21 January 2026.
  91. ↑ O'Neill, Joseph T.; et al. (1976). MUMPS language standard. Gaithersburg, MD: U.S. Dept. of Commerce, National Institute of Standards and Technology. sec. 3.3.1 Arithmetic Binary Operators. doi:10.6028/NBS.HB.118.
  92. ↑ "Chapter 3: The NASM Language". NASM - The Netwide Assembler version 2.15.05.
  93. ↑ "system". nim-lang.org. Retrieved 15 June 2026.
  94. ↑ "std/math". nim-lang.org. Retrieved 15 June 2026.
  95. ↑ "std/math". nim-lang.org. Retrieved 15 June 2026.
  96. ↑ "OCaml library: Stdlib". Ocaml.org. Retrieved 19 February 2022.
  97. ↑ "OCaml library : Int". ocaml.org. Retrieved 10 October 2026.
  98. ↑ "OCaml library: Stdlib". Ocaml.org. Retrieved 19 February 2022.
  99. ↑ "OCaml library : Float". ocaml.org. Retrieved 10 October 2026.
  100. ↑ Perl documentation
  101. ↑ "POSIX - Perl interface to IEEE Std 1003.1 - Perldoc Browser". perldoc.perl.org. Retrieved 22 May 2026.
  102. ↑ "PHP: Arithmetic Operators - Manual". www.php.net. Retrieved 20 November 2021.
  103. ↑ "PHP: fmod - Manual". www.php.net. Retrieved 20 November 2021.
  104. ↑ "Mod". www.purebasic.com. Retrieved 22 July 2026.
  105. ↑ "EuclideanRing".
  106. ↑ "6. Expressions". Python documentation. Retrieved 21 January 2026.
  107. ↑ "math — Mathematical functions". Python documentation. Retrieved 21 January 2026.
  108. ↑ "math — Mathematical functions". Python documentation. Retrieved 21 January 2026.
  109. ↑ QuantumWriter. "Expressions". docs.microsoft.com. Retrieved 11 July 2018.
  110. ↑ "R: Arithmetic Operators". search.r-project.org. Retrieved 24 December 2022.
  111. ↑ "4.3 Numbers". docs.racket-lang.org. Retrieved 22 July 2026.
  112. ↑ "4.3.2 Generic Numerics". docs.racket-lang.org. Retrieved 22 July 2026.
  113. ↑ "4.3.2 Generic Numerics". docs.racket-lang.org. Retrieved 22 July 2026.
  114. ↑ "Operator expressions - The Rust Reference". doc.rust-lang.org. Retrieved 21 January 2026.
  115. ↑ "F32 - Rust".
  116. 1 2 r6rs.org
  117. ↑ "Shell Command Language". pubs.opengroup.org. Retrieved 5 February 2021.
  118. 1 2 ANSI INCITS 319-1998 (R2002): Information Technology - Programming Languages - Smalltalk. American National Standards Institute (ANSI). 1998.
  119. ↑ "Solidity Documentation". docs.soliditylang.org. Retrieved 17 October 2024.
  120. ↑ "Apple Developer Documentation". developer.apple.com. Retrieved 20 November 2021.
  121. ↑ "Apple Developer Documentation". developer.apple.com. Retrieved 20 November 2021.
  122. ↑ "Apple Developer Documentation". developer.apple.com. Retrieved 20 November 2021.
  123. ↑ "mathop manual page - Tcl Mathematical Operator Commands". www.tcl-lang.org. Retrieved 22 May 2026.
  124. ↑ "expr manual page - Tcl Built-In Commands". www.tcl-lang.org. Retrieved 22 May 2026.
  125. ↑ "mathop manual page - Tcl Mathematical Operator Commands". www.tcl-lang.org. Retrieved 22 May 2026.
  126. ↑ "mathfunc manual page - Tcl Mathematical Functions". www.tcl-lang.org. Retrieved 22 May 2026.
  127. 1 2 Rossberg, Andreas, ed. (19 April 2022). "WebAssembly Core Specification: Version 2.0". World Wide Web Consortium. § 4.3.2 Integer Operations.
  128. ↑ "Mod — Xojo documentation". documentation.xojo.com. Retrieved 15 October 2026.
  129. ↑ "Zig Documentation". Zig Programming Language. Retrieved 18 December 2022.
  130. 1 2 "Mod". Wolfram Language & System Documentation Center. Wolfram Research. 2020. Retrieved 8 April 2020.

External links

  • Modulorama, animation of a cyclic representation of multiplication tables (explanation in French)
Retrieved from "https://en.wikipedia.org/w/index.php?title=Modulo&oldid=1381283025"
Categories:
  • Computer arithmetic
  • Operators (programming)
  • Modular arithmetic
  • Operations on numbers
Hidden categories:
  • Articles with short description
  • Short description matches Wikidata
  • Use dmy dates from October 2026
  • Articles with example C++ code
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.