Mod and Modulus (Float functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (match syntax diagram to revised template; fix tags and links)
Line 1: Line 1:
{{Template:Float:Mod and Modulus subtitle}}
{{Template:Float:Mod and Modulus subtitle}}


These [[Intrinsic classes|intrinsic]] functions return the remainder
The <var>Mod</var> and <var>Modulus</var> <var>[[Intrinsic classes|intrinsic]]</var> functions return the remainder from the division of the method object by the method argument. The numbers to be divided are first rounded to an integer, including zero, so the remainder is always an integer or zero.
from the division of the method object by the method argument.
The numbers to be divided are first rounded to an integer, including zero,
so the remainder is always an integer or zero.


''Mod'' is a synonym for ''Modulus''.
<var>Mod</var> is a synonym for <var>Modulus</var>.


The [[Div (Float function)|Div function]] returns the integral quotient of a division.
The Modulus function is available as of version 7.3 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:Float:Mod syntax}}
{{Template:Float:Mod syntax}}
Line 16: Line 10:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%mod </th>
<tr><th>%number</th>
<td>A variable to receive the integral remainder of the quotient of ''number'' / ''num''. </td></tr>
<td>A variable to receive the integral remainder of the quotient of <var class="term">float</var> / <var class="term">number</var>. </td></tr>
<tr><th>float</th>
<td>A Float value to be divided by the method argument, <var class="term">number</var>. </td></tr>
<tr><th>number </th>
<tr><th>number </th>
<td>A Float value to be divided by the method argument, ''num''. </td></tr>
<tr><th>num </th>
<td>A non-zero numeric value. A value of 0, or a value that rounds down to 0, causes a request cancellation.</td></tr>
<td>A non-zero numeric value. A value of 0, or a value that rounds down to 0, causes a request cancellation.</td></tr>
</table>
</table>
==Usage notes==
<ul><li><var>Mod</var> / <var>Modulus</var> are available as of <var class="product">[[Sirius Mods|"Sirius Mods"]]</var> Version 7.3.</ul>
==Examples==
==Examples==
The following statement returns to %z the remainder from the division of
<ol><li>The following statement returns to <code>%z</code> the remainder from the division of the number in <code>%x</code> (rounded) by the number in <code>%y</code> (rounded):
the number in %x (rounded) by the number in %y (rounded):
<p class="code">  %z = %x:mod(%y)</p>
    %z = %x:mod(%y)
<li>The following statement returns '<code>-1</code>' to <code>%z</code>:
The following statement returns ''-1'' to %z:
<p class="code">  %z = -191.4:mod(2.0)</p>
    %z = -191.4:mod(2.0)
<li>The following displays the quotient and remainder when dividing <code>9997</code> by <code>7</code>:
The following displays the quotient and remainder when dividing 9997 by 7:
<p class="code">begin
  b
   %dividend is float
   %dividend is float
   %divisor  is float
   %divisor  is float
   %dividend = 9997
   %dividend = 9997
   %divisor  =  7
   %divisor  =  7
   [[PrintText statement|printText]] {~} = {%dividend:div(%divisor)}
   printText {~} = {%dividend:div(%divisor)}
   printText {~} = {%dividend:mod(%divisor)}
   printText {~} = {%dividend:mod(%divisor)}
  end
end</p>
so displays:
so displays:
  %dividend:div(%divisor) = 1428
<p class="output">%dividend:div(%divisor) = 1428
  %dividend:mod(%divisor) = 1
%dividend:mod(%divisor) = 1</p></ol>


==See also==
==See also==
<ul><li>The <var>[[Div (Float function)|"Div function"]]</var> returns the integral quotient of a division.
<li><var>PrintText</var> is described in the <var>[[Intrinsic classes#printtext|"System Intrinsic Class"]]</var>.</ul>
{{Template:Float:Mod and Modulus footer}}
{{Template:Float:Mod and Modulus footer}}

Revision as of 01:26, 4 February 2011

Remainder of integer division (Float class)


The Mod and Modulus intrinsic functions return the remainder from the division of the method object by the method argument. The numbers to be divided are first rounded to an integer, including zero, so the remainder is always an integer or zero.

Mod is a synonym for Modulus.

Syntax

%number = float:Mod( divisor)

%number = float:Modulus( divisor)

Syntax terms

%number A variable to receive the integral remainder of the quotient of float / number.
float A Float value to be divided by the method argument, number.
number A non-zero numeric value. A value of 0, or a value that rounds down to 0, causes a request cancellation.

Usage notes

Examples

  1. The following statement returns to %z the remainder from the division of the number in %x (rounded) by the number in %y (rounded):

    %z = %x:mod(%y)

  2. The following statement returns '-1' to %z:

    %z = -191.4:mod(2.0)

  3. The following displays the quotient and remainder when dividing 9997 by 7:

    begin %dividend is float %divisor is float %dividend = 9997 %divisor = 7 printText {~} = {%dividend:div(%divisor)} printText {~} = {%dividend:mod(%divisor)} end

    so displays:

    %dividend:div(%divisor) = 1428 %dividend:mod(%divisor) = 1

See also