Jump to content

Talk:Modulo

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Remainder algorithms for various moduli

[edit]

Such as number modulo 3 := sum of the digits (decimal base)
Example: 62837 mod 3 = 6+2+8+3+7 mod 3 = 26 mod 3 = 2+6 mod 3 = 8 mod 3 = 2

Another: number modulo 7 := number lest the last digit - 2 * last digit (decimal base)
Example: 62837 mod 7 = 6283-14 mod 7 = 6269 mod 7 = 626-18 mod 7 = 608 mod 7 = 60-16 mod 7 = 44 mod 7 = 2

Ïnteresting would be an algorithm for numbers modulo 31; with that you could calculate in your head certain check digits to forge a social security number in situ...


please read this before further action on the article

[edit]

This Modulo operation page was created because there was a need to separate the many meanings of the word "modulo" which were all put together in the articles modulo and modular arithmetic with lots of overlap, ambiguity, and incoherence. As result, the modulo page was put (and still is) on the list Wikipedia:Pages needing attention/Mathematics, although ever since it is been significantly improved.

The biggest two mistakes done by the authors contributing to modular arithmetic was to not read the article before modifying it, and not knowing what "modular arithmetic" acually means. As consequence, I am sorry to say this, but the very best version of the page modular arithmetic was the very first.

This page now contains exclusively information about the remainder function in computer science, no more no less. This is according to the belief that separate matters need to be kept in different places in order to avoid confusion.

Care has been taken in this article to refer to the proper place discussing the relationships between the many meanings of modulo.

If by any means you do not agree with creating this article, please express your opinion before attepting to delete this article or to revert it to the form it was before the cleanup. Thank you. Oleg Alexandrov 04:20, 3 Jan 2005 (UTC)

Thank you for separating this out; a separate article for modulo-as-used-in-computing should have existed from the start. As one of the people who upset you by expanding and rephrasing parts of the original article in ways that reflected my ignorance of modular arithmetic, I apologize for upsetting your delicate sensibilities.
However, your implicit insistence that computer programmers (and users of calculators with 'mod' buttons) be well-versed in the nuances of modular arithmetic and the ways in which modulo operators & functions both refine and place arbitrary constraints on the pure mathematical theory is missing the point of Wikipedia, and putting the cart before the horse. I came here as a programmer looking to better understand why "a % b" produced (to me) weird results when one of the operands was negative. You seem to be of the opinion that I should already know the answer, or that it was perfectly clear from the original description of modular arithmetic. It was not (or at least, was predicated on a more thorough understanding of remainder than the average high school graduate is likely to have). - mjb 19:38, 20 Jan 2005 (UTC)
Hi there. I am happy you agree that the articles should have been separated. I see your point above. The original problem is that "modulo" means so many things to so many people, so it is hard to make everybody happy. Some of the answers to your questions should have been on the remainder page, rather than on modular arithmetic. I will put more stuff on that page soon.
We can continue in the discussion I just started on Talk:Modular arithmetic about the future of that page. Oleg Alexandrov | talk 20:30, 20 Jan 2005 (UTC)
Hi there. Again, you have point. Could you take a look at the remainder page and let me know what you think. I am sorry if you thought I am kind of elitist or something. I do think though that the remainder page is a better place to talk about your mod issue. This because modular arithmetic heavily relies on the remainder concept, but is, in itself, much more than just the remainder issue. Looking forward to feedback. Cheers, Oleg Alexandrov | talk 23:22, 20 Jan 2005 (UTC)

Remainders for non-integers

[edit]

I've edited both this article (Modulo operation) and remainder in order to make them both more encyclopedic and to explain things in a way that should make it suitable for the audiences likely to be reading the articles (those whose level of understanding is about where mine was before I started researching the articles). Please review the new versions and see if there are any errors.

One major change I made in this article was an attempt to address the fact that it stated that a and n must be integers. Computers actually also allow floating point, and perhaps even complex numbers, to be used. For example, mod(5.5, 1.3) returns 0.3 (actually, 0.29999999999999982 on my Win32 Python build, due to inherent limitations of floating-point number representation in a binary storage system, for which I'm sure there's an article on Wikipedia somewhere). What I did not do was make a similar change to the remainder article. I would prefer someone more knowledgable than me to clarify whether, and how, non-integers can be divided to produce a quotient and remainder outside of the context of computing. If you or someone could tackle that, that would be great. Thanks! - mjb 04:15, 30 Jan 2005 (UTC)

I replied on Talk:Remainder. Again, mathematicians don't use these generalizations. Actually, you know what we should add on remainder? Something must be said about remainder when dividing polynomials. That is indeed an existing concept, and a very important one in math. Oleg Alexandrov | talk 05:14, 30 Jan 2005 (UTC)

On what should be moved and to where

[edit]

I recommend moving modular operation to this page near the beginning to first define what the modulo function actually does. I say move it here because modular aritmetic is a far more common thing to be searced for and that page can become a redirect page. The clock arithmetic page should also be made to be a redirect page because clock arithmetic is just another way to say it, and not the correct one I might add. As for what to do with advanced modular arithmetic I think it should be mentioned here and the page made into a redirect as well, because it is just more elaboration on a higher level; nothing truly unique enough to really give it its own page.

Either way I am going to move clock arithmetic here and make it a redirect (if it hasn't already been done) because that really makes the most sense for it as it really is just another, less correct, way of saying modular aritmetic.

Guardian of Light 5 July 2005 14:31 (UTC)

1. modular operation is simply a recently-created redirect to this article; there was never anything else in it, so there is nothing to merge. Is the redirect insufficient?
2. The modulo operation article contains a significant amount of info that is specific to its topic, and it is fairly specialized to the computing field, so it really should remain in a separate article that is merely referenced from the modular arithmetic article. There is nothing to do; nothing needs to be merged. — mjb 5 July 2005 23:54 (UTC)
While the modulo operation does have things in common with modular arithmetic, I would argue that those similarites end at taking the remainder. But even here things are different. Modular arithmetic deals with integers, this article deals mostly with real numbers. I agree with Mjb that this article has a lot of computing specific information which has no place in modular arithmetic. Oleg Alexandrov 6 July 2005 03:21 (UTC)
Yup. I think the modulo operation is also put to use in ways that resemble modular arithmetic, while the operation itself is very remainder-focused. For example, when you have a set of data that is grouped in repeating structures, like an 80×25 grid of character cells in a text display, and you want to know the position (row & column) of the 993rd cell (assume the cells are numbered first by column, then row), the modulo operation is quite useful: row=floor(993÷80) and column=modulo(993÷80) — or column=993 modulo 80. That's a fairly high-level application. A lower-level or more general application would be to find relative offset of a piece of information in any sequential, cyclic data structure, like bits in fixed-width binary values, upon which all primitive datatypes are based. It crops up a lot in binary arithmetic. So you can see (perhaps) how its use quite resembles modular arithmetic in this regard, and the use of the word "modulo" is appropriate as well, but the operation itself is not synonymous with the more general topic of modular arithmetic. — mjb 6 July 2005 05:44 (UTC)
I see your points. Okay, I'm done here then.Guardian of Light 6 July 2005 13:28 (UTC)

Operator Symbols

[edit]

In the section Remainder calculation for the modulo operation, a formula for performing the modulo operation uses a symbol which is apparently the floor function. The symbol encloses the fraction and looks like brackets [] minus the top horizontal lines. This is to suggest adding an internal link to the floor function and/or defining the symbol after the formula. --Sablime 03:13, 1 December 2005 (UTC)[reply]

Done. By the way, one should write ==Operator symbol==, and not ==Operator Symbols==. That if you allow me to pick at minor things also. :) Oleg Alexandrov (talk) 04:02, 1 December 2005 (UTC)[reply]
Thank you for your time and effort. Your edit will help people like me who do not recognize the notation. Also thanks for the capitalization tip. Sablime 04:30, 2 December 2005 (UTC)[reply]

ANSI C

[edit]

I'm not sure that ANSI/ISO C doesn't define the remainder operator for negative values. The draft on http://www.open-std.org/jtc1/sc22/wg14/www/docs/n843.htm says in 6.6.5 [#6] "When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.76) If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a.". In other words a%b = a-(a/b)*b - I fail to see why that is undefined for a<0. Jefischer 16:29, 4 December 2005 (UTC)[reply]

Because you quoted the C99 draft which uses round towards 0 for a/b. The C89 standard allowed an implementation to implement a/b as round towards 0 or round towards -Inf. TomJF 05:31, 8 February 2006 (UTC)[reply]

Years of discussion on comp.lang.c says that you are right :) http://groups.google.co.in/groups/search?q=modulus+negative+comp.lang.c&qt_s=Search —The preceding unsigned comment was added by 203.200.55.101 (talkcontribs) 10:12, 24 April 2006 (UTC).[reply]

fortran 95

[edit]

In fortran 95 there are two modulo operations mod and modulo. The latter always returns a positive number. —The preceding unsigned comment was added by 203.200.55.101 (talkcontribs) 10:12, 24 April 2006 (UTC).[reply]

Pascal

[edit]

The article states "Pascal and Algol68 do not satisfy these for negative divisors". Firstly, It would be helpful to give an example of how Pascal/Algol68 deviate from the definition. Secondly, I've checked this for Delphi Pascal, but Delphi seems to follow C, so I conclude it does satisfy the definition. 80.255.245.177 (talk) 11:08, 7 October 2008 (UTC)[reply]

Raymond T. Boute of the University of Nijmengen wrote a seminal paper on this called "The Euclidean definition of the functions div and mod" which is also referenced in the Wikipedia article (https://biblio.ugent.be/input/download?func=downloadFile&fileOId=452146). In section 2.2 of this paper, Boute presents proof that Algol-68 and both ISO Pascals are violating the conditions for Euclidean Division and he classifies them as "wrong". — Preceding unsigned comment added by 37.161.59.93 (talk) 14:36, 20 October 2013 (UTC)[reply]

Remainder constraint

[edit]

The constraint formula "0 <= |r| < n" is wrong when n<0, i think it shuld be "0 <= |r| < |n|" or something like that. --Martin Rizzo 15:20, 19 May 2006 (UTC)[reply]

I think the equation that says "a = q + nr" is incorrect; shouldn't it be "a = nq + r"? --thesoffish 01:00, 10 September 2008 (UTC)[reply]

Naming

[edit]

"Given two numbers, a and n, a modulo n (abbreviated as a mod n) is the remainder, on division of a by n. "
When referring to 'a' or 'n', a name is helpfull. In the paper of Leijen, Daan (December 3, 2001) (see Notes, reference 2) they are described as

  • 'a' dividend
  • 'n' divisor

--217.140.108.2 10:39, 22 November 2006 (UTC)[reply]

Since no protest has arisen, the naming scheme has been adopted.

FMod

[edit]

Why does FMod redirect to this page? I dont know of the relevance to this article and FMod is a company and computer game Sound Engine. Mloren 05:37, 26 September 2007 (UTC)[reply]

A quick Google search reveals that fmod() is a floating-point (not integer) remainder function found in several(?) programming languages. It would be fine to set up a real FMod page for the company and sound engine; just use a template like this one at the very top of that article, like this:
{{for|the fmod function in computer programming languages|modulo operation}}
It will result in a message like this: For the fmod function in computer programming languages, see modulo operation.mjb 06:15, 26 September 2007 (UTC)[reply]
I've changed the redirects as described above. I thought that was more likely to be what was intended, and Google returns FMOD the audio thing earlier. Dhollm (talk) 21:05, 5 April 2009 (UTC)[reply]

MS Excel

[edit]

Since when is Excel a programming language? It's an application that some naive users might think of as a programming language.

--BigDumbDinosaur

It has the ability to have some code written into it, and perform calculations based on that code, thus it has its own unnamed programming language, so people call it excel, for lack of a better name. Black.jeff (talk) 23:58, 25 April 2009 (UTC)[reply]

I have no backing evidence for this, but I would suspect that functionality is provided by VBScript or some Windows link libraries. -Rushyo 217.41.21.125 (talk) 11:09, 2 October 2009 (UTC)[reply]
It's actually provided by VBA (Visual Basic for Applications), which is present in several Microsoft Office applications -Cedgin (talk) 20:46, 11 May 2012 (UTC)[reply]

Floating-point modulo should be added to table

[edit]

Currently the table only does integer modulo operators. (In some languages the floating-point modulo operator is the same as the integer modulo operator; whereas in other languages it is different.) For example, in C, the fmod() function is used to perform floating-point modulo (the % operator won't work); but it is not listed in the table. It is useful to know, not only (1) what the floating-point modulo operators are in these languages, but also (2) whether they follow the sign of the divisor or dividend, in the same way it is listed for the integer modulo operators. I am not sure whether the floating-point versions should be added into the table alongside the integer ones (and maybe have some way to indicate which is which); or to have a separate section or table for floating-point operators altogether. --164.67.154.134 (talk) 21:40, 8 May 2009 (UTC)[reply]

Assembly language

[edit]

I made a long research to use the Modulo operator in Assembly language and the closest I found was the DIV operator however it's not available on the simple educational Assembler PEP8 [1] (French operators instruction Chapitre 7 in http://www.er.uqam.ca/nobel/k20250/Notes_cours.html).

Is there a simpler way of doing a modulo ? Perhaps doing bitwise operations ? --DynV (talk) 19:02, 12 June 2009 (UTC)[reply]

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

[edit]

This formula does not work if x is negative in languages where % uses the sign of the dividend. How can the C compilers use it? Do they use it only when they can prove that x is positive or only in earlier revisions than C99? Jaan Vajakas (talk) 13:44, 13 September 2009 (UTC)[reply]

Modulo operation expression

[edit]

I contributed (A) and the words 'or equivalent, for environments lacking a mod() function'. Another user edited it to look like (B). Could someone explain to my why is (B) preferred over (A). I thought (A) was the more simplified expression, I'm wrong?

(A) (a/n) - int(a/n)

(B) a - n * int(a/n)

--gary84

Expression (A) is incorrect. Try it with a=12, n=5. (A) gives 0.4 (B) gives 2. -- Schapel (talk) 00:35, 18 January 2010 (UTC)[reply]
Oops. I thought I typed n*(a/n-int(a/n)) . Ok (B) wins. -- gary84 —Preceding undated comment added 01:22, 19 January 2010 (UTC).[reply]
If that's what you typed, (B) is a simplified version of that expression that will work correctly with floating point arithmetic. -- Schapel (talk) 01:28, 19 January 2010 (UTC)[reply]
My first time editing a discussion in wikipedia so sorry I don't know the protocol, but my problem with the given expression:
a - (n * int(a/n))
Is that when your'e using a language that does integer division truncation (java, c, etc) then this won't work. For example, -2 mod 5 should be 3, but if your language does integer truncation, you're left with -2 - (5 * 0), or -2. To fix this, we need to be explicit that we need the floor of the division:
a - (n * floor(a/n))
Which would be -2 - (5 * floor(-0.4)) which is -2 - (5 * -1), which is 3 as we expect. What am I missing? —Preceding unsigned comment added by Rjcarr (talkcontribs) 03:49, 6 November 2010 (UTC)[reply]

x mod y with x<y yields x

[edit]

The following sentence atop the article is incorrect: "The range of numbers for an integer modulo of n is 0 to n − 1." When m>n, n mod m = n. This is not just an artifact of particular programming languages; it is what the (correct) definition atop the page prescribes. Specifically, dividing n by m yields a quotient of 0 and a remainder of n. — Preceding unsigned comment added by 70.121.50.23 (talk) 22:34, 22 March 2017 (UTC)[reply]

should also note that "x mod y" where x<y gives x in Squeek VM (SmallTalk) and other environments —Preceding unsigned comment added by 212.251.127.3 (talk) 14:07, 28 March 2011 (UTC)[reply]

Operator Precedence in Equivalencies section

[edit]

The distributive equivalence ab mod n assumes that the operator mod has a low priority than the multiplication. Is this defined somewhere? I could not find a reference. In doubt, I would suggest adding parenthesis (ab) mod n. Norbert6842 (talk) 13:55, 22 May 2013 (UTC)[reply]

Algol-68 and Pascal DO NOT conform to Euclidean Definition

[edit]

The article states that languages that follow the Euclidean definition introduced in Raymond T. Boute's seminal paper (which is referenced in the article) are marked with the qualifier "always positive".

First, this is a problematic way to describe conformance with the Euclidean definition, because not every definition that results in a remainder that is always positive actually follows the Euclidean definition. It would be better to use a different qualifier to express conformance to the Euclidean Definition. In fact it would be beneficial to restructure the table to include a coloumn "Definition" that would then have the qualifiers "T-Definition", "F-Definition", "E-Definition" (as per Boute's paper) and "Other".

Second, there is a factual error in that Algol-68 and both ISO Pascal variants are marked "always positive" which the article says denotes conformance with Boute's E-Definition, but in fact in section 2.2 of Boute's paper he specifically picks out Algol-68 and both ISO Pascals as being "wrong" and he presents a mathematical proof why they are wrong for each of them. Of course it is correct to say that the remainder for Algol-68 and ISO Pascal is "always positive". But it is incorrect to define "always positive" an indicator for conformance with Boute's Euclidean definition.

If the table was modified to have a "Definition" coloumn as I suggested two paragraphs further up, then Algol-68 and both ISO Pascals would be classified "Other" because none of them conform to the E-Definition. The coloumn that indicates the sign of the remainder could still be kept. Even then it should better be "always non-negative" instead of "always positive" in order to avoid an argument over whether or not zero is positive or negative.

I'd be happy to edit the article accordingly, but I do not have the time to investigate for all these languages what definition they conform to. So, if I was to add the additional coloumn to the table, most entries would remain empty until others can fill them in. Also, I am not sure what happens to the formatting of the page if the table gets another coloumn, because it may then be too wide. So, should I wait for feedback from others first, or simply edit the table accordingly and see what happens? — Preceding unsigned comment added by 37.161.59.93 (talk) 14:55, 20 October 2013 (UTC)[reply]

sometimes called modulus - really?

[edit]

I was wondering who it is that sometimes calls it "modulus" instead of "modulo" (except in error of course)?

As it stands the article seems to be propagating and supporting what seems to be (to me at least) an error. AlexFekken (talk) 06:26, 25 January 2014 (UTC)[reply]

I have heard them get confused all my life. I added a "Distinguish" template on the top of page, but another editor reverted it and kindly told me to discuss it on the talk page before taking such an action. Either we add that, or (even better) we modify the clause you quoted to "sometimes called 'modulus'" with 'modulus' perhaps linked to the page on absolute value. YatharthROCK (talk) 13:47, 21 September 2014 (UTC)[reply]
My apologies for that revert. We all come to the table with different backgrounds and confusions can arise in this Tower of Babel. It turns out that the difficulty I had was not with your intention, but rather with the identification of absolute value and modulus. Talking about the modulus of a real number seems a bit archaic these days (although valid since referring to the modulus of a complex number is still in vogue) so I did not make the connection. I would suggest that the hatnote should point to the Modulus (disambiguation) page, but unfortunately there is a link there which points back to this page. I am not sure as to what the best way to handle this is. Bill Cherowitzo (talk) 17:18, 21 September 2014 (UTC)[reply]
IMO "sometimes called 'modulus'" is simply misplaced. I have fixed this. D.Lazard (talk) 13:59, 21 September 2014 (UTC)[reply]
How is it misplaced? It must be removed since modulus is the absolute value and a unary operation. Further mod (or %) is known as modulo operator which would be suitable.DataWiz (talk) 09:21, 11 June 2019 (UTC)[reply]
After my edit, "sometimes called 'modulus'" was correctly placed, and before to remove this phrase, you have moved it in a wrong place. The fact that "modulus" has other meanings in other context does not mean that it is not used in the context of modulo operation. Thus, I have restored the phrase, with a link to this meaning of "modulus".
Note that "modulo" is the ablative of "modulus" and means originally "obtained by applying a modulus".
That actually does make sense, thank you. AlexFekken (talk) 03:56, 22 December 2022 (UTC)[reply]

Misconception of misconceptions

[edit]

The section "Common misconceptions" presents two pretty silly issues. In the second, the expression 3-1 mod 5 neither occurs in the formular above nor is it 2. Nonsense. The first is not very useful either. I can hardly imagine that this unintuitive formular could be a frequent misconception. Removing the whole section. Towopedia (talk) 13:28, 10 April 2014 (UTC)[reply]

3-1 mod 5 is the modular inverse of 3 modulo 5, and it _is_ 2. It does occur in the formula (b-1 mod n). I would like to point out that the title of this section is ironic. However I agree that the section was poorly written which warranted removal. — Preceding unsigned comment added by 99.240.216.184 (talk) 00:27, 27 June 2014 (UTC)[reply]

Bold statement - Is it someone's opinion or a general conclusion?

[edit]

"Despite its widespread use, truncated division is shown to be inferior to the other definitions."

I'm not sure if this is a quote from someone, a summary of their opinion, or a general conclusion. It's a rather bold statement. If we're going to have it around, I'd like to have a better sense of its context.

Mdnahas (talk) 16:13, 29 May 2014 (UTC)[reply]


It's a quote from citation 7 (Leijen,) which is summarizing citation 6 (Boute, R.) For more context see citation 7's page 8 (p. 134 of original publication.) It's available from biblio.ugent.be. 99.240.216.184 (talk) 01:37, 25 June 2014 (UTC)[reply]

I might have spotted a mistake (?)

[edit]

In the section "Equivalencies" it says that
(a*b mod n) = ((a mod n)*(b mod n)) mod n.
But for a = 2, b = 1/3 and n = 1 we have
(a*b mod n) = (2/3 mod 1) = 2/3
and
((2 mod 1)*(1/3 mod 1)) mod 1 = ( 0*(1/3 mod 1)) mod 1 = 0.
(I have never commented or edited a Wikipedia page, so if posting this here was not the right thing to do, I apologize.)

— Preceding unsigned comment added by 2001:630:53:B76:5564:5F69:7384:E781 (talk) 00:08, 27 October 2014 (UTC)[reply]

Status - function or operation?

[edit]

Is this concept an operation or a function of two variabiles?--82.137.13.98 (talk) 12:32, 10 June 2017 (UTC)[reply]

Or both?--82.137.13.98 (talk) 12:35, 10 June 2017 (UTC)[reply]

By definition, an operation is a function with arguments taken from the same set A, having values in A. 94.41.239.251 (talk) 00:03, 11 June 2019 (UTC)[reply]

Sign of the remainder follows the sign of the quotient?

[edit]

An ANDF explanatory document states The operators div2 and rem2 are those generally implemented directly by processor instructions giving the sign of the remainder the same as the sign of the quotient.

It is either a misstatement (e.g. the x86 IDIV instruction gives the sign of the remainder the same as the sign of the dividend), or this is a peculiarity worth mentioning in the table.

Was there ever a programming language specifying that the sign of the remainder the same as the sign of the quotient?

--Leob (talk) 23:01, 21 June 2017 (UTC)[reply]

s/Positive/Nonnegative/

[edit]

I have converted all instances of "Positive always" in the table to "Nonnegative always". There was a note saying that this was what was meant, but we don't know that people will read it. It's just barely possible that some implementation somewhere might literally use a "positive always" convention (for example, 10 mod 10 = 10, rather than 0). I would be shocked if any of the entries in the table actually correspond to that convention. However the fact that it's possible is another reason that we should be correct in what we say about it, and not assume that the reader will translate "positive" to "nonnegative". --Trovatore (talk) 06:50, 18 November 2017 (UTC)[reply]

Side note on this, just in case anyone's wondering: In mathematics done in French, and maybe some other languages, I am given to understand that zero is considered "positive". I did a binary search in the history and I think the word "positive" was introduced in this edit by User:Marc van Leeuwen, whose native language I believe is Dutch; I don't know what the convention is there. But in mathematics done in English, without any exceptions I'm aware of, zero is never positive, so we have to say "nonnegative". This is a universal convention in English; it's not like "natural number", where some authors include zero and some do not. Zero is never positive in English. --Trovatore (talk) 07:50, 18 November 2017 (UTC) [reply]

Side comment: in French, zero is not considered as positive. The reality is that "positive" and "negative" are ambiguous, as is "natural number" in English. When disambiguation is needed, French people use "strictement positif" (strictly positive) or "positif ou nul" (positive or zero). D.Lazard (talk) 10:21, 18 November 2017 (UTC) [reply]
Thanks for the clarification. So if negatif is ambiguous, then I suppose so is nonnegatif (pas negatif?), which is why you would need positif ou nul. Even if it's ambiguous, we still wouldn't want to use it in a table like this.
Which does bring up a point for the article. I wonder if "positive or zero" would be better here, too. "Nonnegative" is unambiguous in English, but it gives less-mathematical readers a problem to solve, and we could avoid that. On the other hand, it's wordier. I could live with either. --Trovatore (talk) 20:41, 18 November 2017 (UTC)[reply]
You are reading to much into my edit. Note that this was an entry in the column headed "Result has same sign as" which is assuming a nonzero result; the many cases where the entry is "dividend", so it reads "Result has same sign as dividend", that is not to be taken literally in the case of a zero result either. I admit that "Result has same sign as always positive" is not grammatically correct, while "Result has same sign as always 13" is, but I think the former reads straightforwardly, and is less confusing than "Result has same sign as Euclidean algorithm" which means you need to look up what that means. Marc van Leeuwen (talk) 17:40, 20 November 2017 (UTC)[reply]
Fair enough. I still think "always positive" has too much potential to be misinterpreted. It's true that "same sign as divisor" or "same sign as dividend" has the same problem in theory. I don't know what to do about those. --Trovatore (talk) 21:59, 20 November 2017 (UTC)[reply]

A reason for using floored division

[edit]

The article is missing one of the key reasons for using floored division for modulo operation: , where a, b, and c are integers, always produces the same signed value for c, regardless if b < 0, b = 0, or b > 0. This is why mathematical languages like APL (dates back to the 1960's) use floored division for integer modulo. Rcgldr (talk) 19:01, 5 March 2018 (UTC)[reply]

Faster modulo reduction

[edit]

Just a thought, I haven't implemented this yet:

If we want x mod n, we subtract n from x until the remainder is less than n, but this can take forever...

Using binary however, we can use 'left-shift: n<<k' to maximize 2^k.n, and then safely remove this.

Darcourse (talk) 11:04, 5 November 2018 (UTC)[reply]

This seems to be the long division, written in base 2. See also Integer division (unsigned) with remainder. In any case, this is not a new idea. D.Lazard (talk) 11:32, 5 November 2018 (UTC)[reply]

Should be nominated for best of Wikipedia

[edit]

This article is what a Wikipedia article should be: the Five Ws in clear language. It explains its topic without going astray into complicated underpinnings that other articles are better suited for. It has plenty of examples of How and Why. My only complaint: I do wish the huge table at the beginning could be collapsed by default on desktop browsers. (It already works well on mobile as every section starts collapsed). Ben (talk) 22:22, 5 November 2018 (UTC)[reply]

I suggest reviewing the languages section

[edit]

I suggest reviewing the languages section. I found at least one entry, which in fact was a commercial product, which was just using JavaScript, and not a programming language on its own. Was added with this edit some time ago: http://en.wiki.x.io/w/index.php?title=Modulo_operation&diff=763594470&oldid=762711874 Maybe other products were also sneaked in. --93.219.42.240 (talk) 09:30, 23 April 2020 (UTC)[reply]

Is the Modulo Arithmetic?

[edit]

Is the Modulo really a binary, arithmetic operation? --AXONOV (talk) 12:34, 14 August 2021 (UTC)[reply]

Modulo operation is certainly a binary operation, as it takes two arguments for producing a single result. Certainly also, it belongs to arithmetic. However, as there is no general definition of an "arithmetic operation", it is a personal choice to decide whether it may be called an arithmetic operation. D.Lazard (talk) 14:05, 14 August 2021 (UTC)[reply]

The graphs of the quotients and remainders from different types of division would be even better if the divisor was annotated on the x-axis.

[edit]

In the "Variants of the definition", the graphs of the quotients and remainders from different types of division are great! But they would be even better if the divisor was annotated on the x-axis as I have done in this [Desmos graph](https://www.desmos.com/calculator/vurfgbki14). It would help show, for example, that all definitions have the property "mn mod n = 0".

"Common pitfalls" should lose C-specific example

[edit]

The "Common pitfalls" section is written in C (which arguably is wrong), but at least most of it uses generic concepts: functions, booleans, integers, equality, logical-or, and so on. The last example, however, uses a very C-specific concept: that non-zero integer values are "true" and can be directly converted into boolean values. Not all languages will let you directly convert an integer into a boolean, and theoretically even those that do might use a different convention. (In UNIX shells, for instance, if, while, and related operators regard zero as true and non-zero as false.) Jordan Brown (talk) 03:15, 13 April 2022 (UTC)[reply]

Move discussion in progress

[edit]

There is a move discussion in progress on Talk:Modulo (mathematics) which affects this page. Please participate on that page and not in this talk page section. Thank you. —RMCD bot 16:00, 28 December 2022 (UTC)[reply]

Recent move/merger/whatever it was

[edit]

I missed the recent discussion, probably because I didn't have modulo (mathematics) watchlisted. I'm not sure what's the best final state, but I'm pretty sure this isn't it, for two main reasons:

  • First, modulo is not a good name for any sort of serious article. Per WP:NOUN, article titles should ordinarily be nouns or noun phrases. "Modulo" is, what, an adverb, I guess? It's fine for it to redirect somewhere or be a disambig page, but to have it be the name of an article with serious content is not optimal.
  • Second, there's no good justification for a split between modulo and modulo (mathematics) (unless modulo is a disambig page). Modulo is not really used outside of mathematics, except the "jargon" usage, which doesn't need an article at all, WP not being a dictionary and all that.

I think there are two reasonable ways to go here:

The current content of modulo (mathematics) should be nuked — we don't write articles just to document jargon. Or rather, it can be worked into other articles, but it should not stand alone. --Trovatore (talk) 18:04, 18 January 2023 (UTC)[reply]
Sorry for the flow-of-consciousness editing — looking back, I think my first alternative doesn't make sense, and I put it there because I had wrong assumptions about what modulo (mathematics) was about. I guess it could still work to have a single article at modulo operation, and treat linear congruences there, but it's probably not ideal (ha ha) and I would be propending for the second alternative. --Trovatore (talk) 18:19, 18 January 2023 (UTC)[reply]

I fully agree with Trovatore's concerns. Here are some complements:
  • Modulo (mathematics) is an article that contains almost no mathematics. So this is a confusing title. I agree to nuke this article and to redirect the title elsewhere. Imo, the best target is, for the moment, Modular arithmetics.
  • Modulo operation is about computer implementations of the modulo operation defined in Modular arithmetics. So, it must be moved to Modulo operation (programming). Otherwise, the title is confusing for people interested in mathematics.
  • More generally, "modulo" has two different related meanings. After a relation, such as in it specifies an equivalence relation and this means that the two arguments of equivalence belong to the same equivalence class (the equals sign is often used for emphasizing on the equality of the equivalence classes. After an elemnt (expression) such as in it denotes a representative of the equivalence class (this is the "modulo operation" of programming languages), or, sometimes, the equivalence class itself, or the image of the element in a quotient structure.
  • Both general meanings are generalizations of the original meanings in modular arithmetics (this is historically the primary topic), and are used in many areas of mathematics. So it seems useless to have a specific article. A solution could be to expand the above summary into a section "Generalization" of Modular arithmetics.
In summary, my proposition is
D.Lazard (talk) 22:14, 18 January 2023 (UTC)[reply]
Hmm, I agree with most of it. I'm not sure about the first point. Is there anything else "modulo operation" can reasonably mean? We don't put parenthetical disambiguators on titles that aren't ambiguous. Also, it's not clear that it's just about programming; I imagine it wouldn't be hard to find mathematics papers that found a use for the operation a mod b. --Trovatore (talk) 17:55, 19 January 2023 (UTC)[reply]
For many people, "Modulo operation" can mean "Arithmetic operation modulo n". So, a disambiguation is needed. This disambiguation can be done, as I suggested, by adding a parenthetical complement. A probably better solution is to create a redirect Modulo-n operation (the formulation Operation modulo n could better correspond to the common terminology, but having the same first word is better for disambiguating; in any case, both redirects can be created). The target of these redirects must be Modular arithmetic, and, more precisely a section Modular arithmetic § Arithmetic modulo n. Unfortunately this section does not exist yet. It is one of my next tasks to write it. D.Lazard (talk) 14:22, 21 January 2023 (UTC)[reply]
I think it's pretty clear that the operation a mod b is going to be the primary topic for the search term "modulo operation". I don't think the current article is necessarily "about" programming; it happens to go into possibly excessive detail about how the operation is handled in various programming contexts, but I'd say it's "about" the operation itself, which is not specific to programming. The text of the current article might need some cleanup but that's not a consideration when deciding titles.
I don't think "modulo-n operation" is a workable solution, because the divisor has no special variable name. --Trovatore (talk) 17:20, 21 January 2023 (UTC)[reply]

Euclidean division is the LEAST regular approach

[edit]

https://i.imgur.com/rX8KRgE.png

Regardless of the signs of either the (D)ividend or the (d)ivisor, both truncated division and floored division give consistent quotients (within each approach) when one multiplies

   (D)ividend      ( -1 )            (D)ividend x ( -1 )
  ------------- x --------    ——>   ---------------------
    (d)ivisor      ( -1 )             (d)ivisor x ( -1 )

Only Euclidean division utterly fails at the identity rule. How could anyone claim it's the most "regular" ?! 2603:7000:3C3D:4840:0:0:0:3C3 (talk) 05:58, 23 July 2024 (UTC)[reply]

Ask to the authors quoted in the article. This is their opinion, not a claim of Wikipedia. D.Lazard (talk) 11:13, 23 July 2024 (UTC)[reply]
well … was my point valid ? if so, perhaps an extra bit of short text near the original quote to note the glaring flaw that was completely overlooked by the author when drawing his conclusions ?
Modulos are meaningful only once other more fundamental mathematic properties have been satisfied. A numeric one (1) for multiplication identity is true for real numbers and complex numbers (and the corresponding identity matrix), and to my limited best understanding, is also applicable for advanced math constructs like rings, fields, etc.
The original author, despite being a math professor, was completely willing to overlook this most fundamental property about mathematics. And I've noticed user < Mdnahas > above also took issue with this quote. The conclusion drawn is also far from being the consensus - for starters, a Knuth quote from this same article shows that he was recommending an approach other than Euclidean. Nor does the site WolframAlpha use Euclidean for its default approach either.
When quotes are far from any generally accepted consensus, wikipedia has an obligation to provide some analysis on the pros and cons of the approaches, instead of simply taking one's quote(s) as-is (which may give the appearance this opinion represents the broad consensus, and/or that dissenting viewpoints are far too fringe to be worth a discussion of their merits). 2603:7000:3C3D:4840:0:0:0:3C3 (talk) 07:47, 3 August 2024 (UTC)[reply]

Incorrect rendering of floor function

[edit]

In the description of Knuth's floored division, the floor function is written inline as ⌋⌊, but this renders incorrectly with the two characters in the wrong order (i.e. ⌊⌋). I'm not sure why this would be unless the text has somehow entered right-to-left mode. I didn't just edit this to fix the problem as the source would then look incorrect and the change could easily be reverted. Does anyone understand why the rendering behaves this way? Glyn normington (talk) 01:49, 14 August 2024 (UTC)[reply]

This may be a bug of your browser, since not all browsers render correctly such special characters. Thus I have edited the article by using latex for these special characters. D.Lazard (talk) 11:28, 14 August 2024 (UTC)[reply]