<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Help%3AModulo_and_round</id>
	<title>Help:Modulo and round - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Help%3AModulo_and_round"/>
	<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Help:Modulo_and_round&amp;action=history"/>
	<updated>2026-05-03T14:09:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Help:Modulo_and_round&amp;diff=1710&amp;oldid=prev</id>
		<title>Wadmin: 1 revision(s)</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Help:Modulo_and_round&amp;diff=1710&amp;oldid=prev"/>
		<updated>2006-07-19T05:34:34Z</updated>

		<summary type="html">&lt;p&gt;1 revision(s)&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 05:34, 19 July 2006&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Wadmin</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Help:Modulo_and_round&amp;diff=1709&amp;oldid=prev</id>
		<title>Omniplex: omitting spaces doesn't improve readability</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Help:Modulo_and_round&amp;diff=1709&amp;oldid=prev"/>
		<updated>2006-06-24T02:42:52Z</updated>

		<summary type="html">&lt;p&gt;omitting spaces doesn&amp;#039;t improve readability&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{h:h}}[[Category:Editor handbook]]&lt;br /&gt;
&lt;br /&gt;
The MediaWiki extension [[m:ParserFunctions|ParserFunctions]] enables users to perform simple mathematical [[m:Help:Calculation|computations]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;expr and #ifexpr allow mod and round.&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;6px&amp;quot; border=1 style=&amp;quot;border:1px solid #C0C0C0; border-collapse:collapse;&amp;quot;&lt;br /&gt;
! ''Operator''&lt;br /&gt;
! ''Operation''&lt;br /&gt;
! ''Example''&lt;br /&gt;
|-&lt;br /&gt;
! [[w:en:Modulo operation|mod]]&lt;br /&gt;
|| &amp;quot;Modulo&amp;quot;,&amp;amp;#160;remainder&amp;amp;#160;of&amp;amp;#160;division after truncating both operands to an integer.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;Caveat, '''mod''' is different from all programming languages. This has been fixed (but needs to be committed), see [[bugzilla:6068]]. &lt;br /&gt;
||{{evaldemo|#expr: 30 mod 7|&amp;amp;#61;}}&amp;lt;br /&amp;gt;{{evaldemo|#expr: -8 mod -3|&amp;amp;#61;}}&amp;lt;br /&amp;gt;{{evaldemo|#expr: -8 mod +3|&amp;amp;#61;}}&amp;lt;br /&amp;gt;{{evaldemo|#expr: 8 mod 2.7|&amp;amp;#61;}} (should be 2.6)&amp;lt;br /&amp;gt;{{evaldemo|#expr: 8 mod 3.2|&amp;amp;#61;}} (should be 1.6)&amp;lt;br /&amp;gt;{{evaldemo|#expr: 8.9 mod 3|&amp;amp;#61;}} (should be 2.9)&lt;br /&gt;
|-&lt;br /&gt;
! round&lt;br /&gt;
|| Rounds off the number on the left to the power of 1/10 given on the right&lt;br /&gt;
||{{evaldemo|#expr: 30/7 round 3|&amp;amp;#61;}}&amp;lt;br /&amp;gt;{{evaldemo|#expr: 30/7 round 0|&amp;amp;#61;}}&amp;lt;br /&amp;gt;{&amp;amp;#123;&amp;lt;small&amp;gt;&amp;amp;#160;&amp;lt;/small&amp;gt;&amp;lt;code&amp;gt;#expr:&amp;amp;#160;3456&amp;amp;#160;round&amp;amp;#160;-2&amp;lt;/code&amp;gt;&amp;amp;#125;}&amp;amp;#160;&amp;amp;#61;&amp;amp;#160;{{#expr: 3456 round -2}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Spaces around mod and round are good for readability but not needed for working properly:&lt;br /&gt;
*{{evd|#expr:7mod3}}&lt;br /&gt;
*{{evd|#expr:7.5round0}}&lt;br /&gt;
&lt;br /&gt;
Precedence:&lt;br /&gt;
*{{evaldemo|#expr:1.234 + 1.234 round 1 + 1 }}&lt;br /&gt;
&lt;br /&gt;
(first additions, then round)&lt;br /&gt;
&lt;br /&gt;
*{{evaldemo|#expr:3 * 4 mod 10 * 10 }}&lt;br /&gt;
&lt;br /&gt;
(mod and multiplication have equal precedence, evaluation from left to right)&lt;br /&gt;
&lt;br /&gt;
To remind the reader of the precedence, one might write:&lt;br /&gt;
*{{evaldemo|#expr:1.234+1.234 round 1+1 }}&lt;br /&gt;
*{{evaldemo|#expr:2 + 3*4mod10*10 + 5}}&lt;br /&gt;
&lt;br /&gt;
;When using spaces where there is precedence, the layout of the expression may be confusing&amp;amp;#58;&lt;br /&gt;
:{{evaldemo|#expr:23+45 mod 10}}&lt;br /&gt;
;Instead one can write&amp;amp;#58;&lt;br /&gt;
:{{evaldemo|#expr:23 + 45 mod10}}&lt;br /&gt;
;or simply use parentheses&amp;amp;#58;&lt;br /&gt;
:{{evaldemo|#expr:23 + (45 mod 10)}}&lt;br /&gt;
&lt;br /&gt;
==Mod==&lt;br /&gt;
To get a positive mod even for a negative number, use e.g. (700000 + x) mod7 instead of x mod7. The range of the result is now 0-6, provided that x &amp;gt; -700000.&lt;br /&gt;
&lt;br /&gt;
Alternatively, use&lt;br /&gt;
*6 - ( 700006 - x ) mod7&lt;br /&gt;
or&lt;br /&gt;
*(x - 700006) mod7 + 6.&lt;br /&gt;
The range of the result is  0-6, provided that x &amp;lt; 700006.&lt;br /&gt;
&lt;br /&gt;
Working for all x is:&lt;br /&gt;
*(x mod7 + 7) mod7&lt;br /&gt;
&lt;br /&gt;
==Round==&lt;br /&gt;
*{{evd|#expr:2.5 round 0}}&lt;br /&gt;
*{{evd|#expr:-2.5 round 0}}&lt;br /&gt;
&lt;br /&gt;
To round an integer plus one half for x &amp;gt; -100000 toward plus infinity, use:&lt;br /&gt;
*(x + 100000 round 0) - 100000&lt;br /&gt;
and to round an integer plus one half for x &amp;lt; 100000 toward minus infinity, use:&lt;br /&gt;
*(x - 100000 round 0) + 100000&lt;br /&gt;
&lt;br /&gt;
To round x toward minus infinity, use:&lt;br /&gt;
*x + ( x != x round 0 ) * ( ( ( x - .5 ) round 0 ) - x )&lt;br /&gt;
and toward plus infinity&lt;br /&gt;
*x + ( x != x round 0 ) * ( ( ( x + .5 ) round 0 ) - x )&lt;br /&gt;
&lt;br /&gt;
If x is a long expression this multiplies the length by 5! Under conditions for x there are alternatives:&lt;br /&gt;
&lt;br /&gt;
To round x &amp;gt; -100000 toward minus infinity, use:&lt;br /&gt;
*(x - 100000.5 round 0) + 100000&lt;br /&gt;
and to round x &amp;lt; 100000 toward plus infinity, use:&lt;br /&gt;
*(x + 100000.5 round 0) - 100000&lt;br /&gt;
&lt;br /&gt;
If x is a multiple of 1/n with n&amp;lt;1000 we can round toward minus infinity with:&lt;br /&gt;
*x - .499 round 0&lt;br /&gt;
&lt;br /&gt;
For arbitrary n &amp;gt; 1 we can choose instead of -.499 any number between -.5 and -.5 + 1/n.&lt;br /&gt;
&lt;br /&gt;
To find the largest multiple of 7 not larger than x (i.e. to round toward minus infinity to a multiple of 7) we can do:&lt;br /&gt;
*((x-3)/7 round 0) * 7&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*{{tim|mod}}&lt;br /&gt;
*[[m:Category:Mathematical templates]]&lt;br /&gt;
*[[w:en:Category:Mathematical templates]]&lt;br /&gt;
{{h:f|enname=Modulo and round}}&lt;/div&gt;</summary>
		<author><name>Omniplex</name></author>
		
	</entry>
</feed>