Talk:Modulo

message: 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)
replies: text: 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)
thread_title: Remainders for non-integers

message: 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)
replies: text: 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)
replies: text: 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)
thread_title:  Operator Symbols 

message: 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)
replies: text: 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)
thread_title: ANSI C

message: 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 (talk • contribs) 10:12, 24 April 2006 (UTC)
thread_title: fortran 95

message: 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)
thread_title: Pascal

message: 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)
thread_title:  Remainder constraint 

message: "Given two numbers, a and n, a modulo n (abbreviated as a mod n) is the remainder, on division of a by n. " <BR>
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)
thread_title:  Naming 

message: 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)
replies: text: 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)
replies: text: 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)
thread_title:  MS Excel 

message: 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)
thread_title:  Floating-point modulo should be added to table 

message: 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  (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)
thread_title:  Assembly language 

message: 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)
thread_title:  x % 2^n == x & (2^n - 1) 

message: 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)
thread_title:  x mod y with x<y yields x 

message: 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)
thread_title:  Operator Precedence in ''Equivalencies'' section 

message: 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)
thread_title:  Algol-68 and Pascal DO NOT conform to Euclidean Definition 

message: 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)
replies: text: 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)
thread_title:  Misconception of misconceptions 

message: "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)
replies: text: 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)
thread_title:  Bold statement - Is it someone's opinion or a general conclusion? 

message: 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)
thread_title:  I might have spotted a mistake (?) 

message: Is this concept an operation or a function of two variabiles?--82.137.13.98 (talk) 12:32, 10 June 2017 (UTC)
replies: text: 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)
thread_title:  Status - function or operation? 

message: 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)
thread_title:  Sign of the remainder follows the sign of the quotient? 

message: The article is missing one of the key reasons for using floored division for modulo operation:  (a + b \ n)mod \ n = a \ mod \ n  = c , 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)
thread_title:  A reason for using floored division 

message: 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)
replies: text: 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)
thread_title:  Faster modulo reduction 

message: 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)
thread_title:  Should be nominated for best of Wikipedia 

message: 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: https://en.wikipedia.org/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)
thread_title:  I suggest reviewing the languages section 

message: Is the Modulo really a binary, arithmetic operation? --AXONOV (talk) ⚑ 12:34, 14 August 2021 (UTC)
replies: text: 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)
thread_title:  Is the Modulo Arithmetic? 

message: 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)
thread_title:  "Common pitfalls" should lose C-specific example 

message: 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)
thread_title:  Move discussion in progress