<?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.divmod.php',
    1 => 'BcMath\\Number::divmod',
    2 => 'Gets the quotient and modulus of an arbitrary precision number',
  ),
  'up' => 
  array (
    0 => 'class.bcmath-number.php',
    1 => 'BcMath\\Number',
  ),
  'prev' => 
  array (
    0 => 'bcmath-number.div.php',
    1 => 'BcMath\\Number::div',
  ),
  'next' => 
  array (
    0 => 'bcmath-number.floor.php',
    1 => 'BcMath\\Number::floor',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/bc/bcmath/number/divmod.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>

 <div class="refsect1 description" id="refsect1-bcmath-number.divmod-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>BcMath\Number::divmod</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="language.types.array.php" class="type array">array</a></span></div>

  <p class="simpara">
   Gets the quotient and remainder of dividing <var class="varname">$this</var> by <code class="parameter">num</code>.
  </p>
 </div>


 
 <div class="refsect1 parameters" id="refsect1-bcmath-number.divmod-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.divmod-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   Returns an indexed <span class="type"><a href="language.types.array.php" class="type array">array</a></span> where the first element is the quotient as a new
   <span class="classname"><a href="class.bcmath-number.php" class="classname">BcMath\Number</a></span> object and the second element is the remainder as a new
   <span class="classname"><a href="class.bcmath-number.php" class="classname">BcMath\Number</a></span> object.
  </p>
  <p class="simpara">
   The quotient is always an integer value, so <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the quotient will
   always be <code class="literal">0</code>, regardless of whether explicitly specify <code class="parameter">scale</code>.
  </p>
  <p class="simpara">
   If <code class="parameter">scale</code> is explicitly specified, <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the
   remainder will be the specified value.
   When the <span class="property"><a href="class.bcmath-number.php#bcmath-number.props.scale">BcMath\Number::scale</a></span> of the result&#039;s remainder 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 remainder
   will be <code class="literal">5</code>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-bcmath-number.divmod-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.divmod-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="methodname"><strong>BcMath\Number::divmod()</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 /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'8.3 / 2.22' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />[</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">] = new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'8'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">divmod</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">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL </span><span style="color: #007700">. </span><span style="color: #DD0000">'8.3 / 8.3' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />[</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</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">)-&gt;</span><span style="color: #0000BB">divmod</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.3'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL </span><span style="color: #007700">. </span><span style="color: #DD0000">'10 / -3' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />[</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">] = new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'10'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">divmod</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</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">8.3 / 2.22
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;3&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;1.34&quot;
  [&quot;scale&quot;]=&gt;
  int(2)
}

8.3 / 8.3
object(BcMath\Number)#2 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;1&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;0.0&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

10 / -3
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(2) &quot;-3&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#1 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;1&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}</pre>
</div>
   </div>
  </div>

  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="methodname"><strong>BcMath\Number::divmod()</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 /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'8.3 / 2.22' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />[</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">] = new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'8'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">divmod</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">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL </span><span style="color: #007700">. </span><span style="color: #DD0000">'8.3 / 8.3' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />[</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</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">)-&gt;</span><span style="color: #0000BB">divmod</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.3'</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL </span><span style="color: #007700">. </span><span style="color: #DD0000">'10 / -3' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />[</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</span><span style="color: #007700">] = new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'10'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">divmod</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">, </span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$quot</span><span style="color: #007700">, </span><span style="color: #0000BB">$rem</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">8.3 / 2.22
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;3&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.3&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

8.3 / 8.3
object(BcMath\Number)#2 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;1&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(6) &quot;0.0000&quot;
  [&quot;scale&quot;]=&gt;
  int(4)
}

10 / -3
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(2) &quot;-3&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#1 (2) {
  [&quot;value&quot;]=&gt;
  string(7) &quot;1.00000&quot;
  [&quot;scale&quot;]=&gt;
  int(5)
}</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-bcmath-number.divmod-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.bcdivmod.php" class="function" rel="rdfs-seeAlso">bcdivmod()</a> - Get the quotient and 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.mod.php" class="methodname" rel="rdfs-seeAlso">BcMath\Number::mod()</a> - Gets the modulus of an arbitrary precision number</span></li>
  </ul>
 </div>


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