<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.bcmath-number.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'bcmath-number.mod.php',
    1 => 'BcMath\\Number::mod',
    2 => 'Gets the modulus of an arbitrary precision number',
  ),
  'up' => 
  array (
    0 => 'class.bcmath-number.php',
    1 => 'BcMath\\Number',
  ),
  'prev' => 
  array (
    0 => 'bcmath-number.floor.php',
    1 => 'BcMath\\Number::floor',
  ),
  'next' => 
  array (
    0 => 'bcmath-number.mul.php',
    1 => 'BcMath\\Number::mul',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/bc/bcmath/number/mod.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="bcmath-number.mod" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">BcMath\Number::mod</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.4.0)</p><p class="refpurpose"><span class="refname">BcMath\Number::mod</span> &mdash; <span class="dc-title">Gets the modulus of an arbitrary precision number</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-bcmath-number.mod-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>BcMath\Number::mod</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.bcmath-number.php" class="type BcMath\Number">BcMath\Number</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$num</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$scale</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="class.bcmath-number.php" class="type BcMath\Number">BcMath\Number</a></span></div>

  <p class="simpara">
   Gets the remainder of dividing <var class="varname">$this</var> by <code class="parameter">num</code>.
   Unless <code class="parameter">num</code> is <code class="literal">0</code>, the result has the same sign
   as <var class="varname">$this</var>.
  </p>
 </div>


 
 <div class="refsect1 parameters" id="refsect1-bcmath-number.mod-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">num</code></dt>
    <dd>
     <span class="simpara">
      The divisor.
     </span>
    </dd>
   
   
    <dt><code class="parameter">scale</code></dt>
    <dd>
     <span class="simpara">
      <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> explicitly specified for calculation results.
      If <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the calculation result will be set automatically.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-bcmath-number.mod-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   Returns the modulus as a new <span class="classname"><a href="class.bcmath-number.php" class="classname">BcMath\Number</a></span> object.
  </p>
  <p class="simpara">
   When the <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the result object is automatically set,
   the greater <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the two numbers used for modulus operation is used.
  </p>
  
  <p class="simpara">
   That is, if the <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span>s of two values are <code class="literal">2</code>
   and <code class="literal">5</code> respectively, the <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the result
   will be <code class="literal">5</code>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-bcmath-number.mod-errors">
  <h3 class="title">Errors/Exceptions</h3>
  
  <p class="para">
   This method throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> in the following cases:
   <ul class="simplelist">
    <li><code class="parameter">num</code> is <span class="type"><a href="language.types.string.php" class="type string">string</a></span> and not a well-formed BCMath numeric string</li>
    <li><code class="parameter">scale</code> is outside the valid range</li>
   </ul>
  </p>
  
  <p class="simpara">
   This method throws a <span class="exceptionname"><a href="class.divisionbyzeroerror.php" class="exceptionname">DivisionByZeroError</a></span> exception if
   <code class="parameter">num</code> is <code class="literal">0</code>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-bcmath-number.mod-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="methodname"><strong>BcMath\Number::mod()</strong></span> example when <code class="parameter">scale</code> is not specified</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$number </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.3'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$ret1 </span><span style="color: #007700">= </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">mod</span><span style="color: #007700">(new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'2.22'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$ret2 </span><span style="color: #007700">= </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">mod</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.3'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ret3 </span><span style="color: #007700">= </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">mod</span><span style="color: #007700">(-</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$number</span><span style="color: #007700">, </span><span style="color: #0000BB">$ret1</span><span style="color: #007700">, </span><span style="color: #0000BB">$ret2</span><span style="color: #007700">, </span><span style="color: #0000BB">$ret3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(BcMath\Number)#1 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;8.3&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;1.64&quot;
  [&quot;scale&quot;]=&gt;
  int(2)
}
object(BcMath\Number)#2 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;0.0&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;3.3&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}</pre>
</div>
   </div>
  </div>

  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="methodname"><strong>BcMath\Number::mod()</strong></span> example of explicitly specifying <code class="parameter">scale</code></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$number </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.3'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$ret1 </span><span style="color: #007700">= </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">mod</span><span style="color: #007700">(new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'2.22'</span><span style="color: #007700">), </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ret2 </span><span style="color: #007700">= </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">mod</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.3'</span><span style="color: #007700">, </span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ret3 </span><span style="color: #007700">= </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">mod</span><span style="color: #007700">(-</span><span style="color: #0000BB">5</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$number</span><span style="color: #007700">, </span><span style="color: #0000BB">$ret1</span><span style="color: #007700">, </span><span style="color: #0000BB">$ret2</span><span style="color: #007700">, </span><span style="color: #0000BB">$ret3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(BcMath\Number)#1 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;8.3&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#2 (2) {
  [&quot;value&quot;]=&gt;
  string(5) &quot;0.000&quot;
  [&quot;scale&quot;]=&gt;
  int(3)
}
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;3&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-bcmath-number.mod-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.bcmod.php" class="function" rel="rdfs-seeAlso">bcmod()</a> - Get modulus of an arbitrary precision number</span></li>
   <li><span class="methodname"><a href="bcmath-number.div.php" class="methodname" rel="rdfs-seeAlso">BcMath\Number::div()</a> - Divides by an arbitrary precision number</span></li>
   <li><span class="methodname"><a href="bcmath-number.divmod.php" class="methodname" rel="rdfs-seeAlso">BcMath\Number::divmod()</a> - Gets the quotient and modulus of an arbitrary precision number</span></li>
   <li><span class="methodname"><a href="bcmath-number.powmod.php" class="methodname" rel="rdfs-seeAlso">BcMath\Number::powmod()</a> - Raises an arbitrary precision number, reduced by a specified modulus</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>