Skip to content

Commit

Permalink
Added bcceil, bcfloor, bcround and bcdivmod
Browse files Browse the repository at this point in the history
  • Loading branch information
SakiTakamachi committed Nov 23, 2024
1 parent 0e09741 commit 9110b52
Show file tree
Hide file tree
Showing 7 changed files with 646 additions and 0 deletions.
91 changes: 91 additions & 0 deletions reference/bc/functions/bcceil.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.bcceil" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bcceil</refname>
<refpurpose>Round arbitrary precision number fractions up</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>bcceil</methodname>
<methodparam><type>string</type><parameter>num</parameter></methodparam>
</methodsynopsis>
<para>
Returns the next highest integer value by rounding up
<parameter>num</parameter> if necessary.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<para>
The value to round.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
num rounded up to the next highest number as a string.
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>ceil</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
echo bcceil('4.3'); // '5'
echo bcceil('9.999'); // '10'
echo bcceil('-3.14'); // '-3'
?>
]]>
</programlisting>
</example>
</para>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>bcfloor</function></member>
<member><function>bcround</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
1 change: 1 addition & 0 deletions reference/bc/functions/bcdiv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ echo bcdiv('105', '6.55957', 3); // 16.007
&reftitle.seealso;
<para>
<simplelist>
<member><function>bcmod</function></member>
<member><function>bcmul</function></member>
</simplelist>
</para>
Expand Down
142 changes: 142 additions & 0 deletions reference/bc/functions/bcdivmod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.bcdivmod" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bcdivmod</refname>
<refpurpose>Get the quotient and modulus of an arbitrary precision number</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>bcdivmod</methodname>
<methodparam><type>string</type><parameter>num1</parameter></methodparam>
<methodparam><type>string</type><parameter>num2</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>scale</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
Get the quotient and remainder of dividing <parameter>num1</parameter> by
<parameter>num2</parameter>.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>num1</parameter></term>
<listitem>
<para>
The dividend, as a string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>num2</parameter></term>
<listitem>
<para>
The divisor, as a string.
</para>
</listitem>
</varlistentry>
&bc.scale.description;
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns an array, the first element is the quotient as a string and the second
element is the remainder as a string.
</para>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<para>
This function throws a <classname>ValueError</classname> in the following cases:
<simplelist>
<member><parameter>num1</parameter> or <parameter>num2</parameter> is not a well-formed BCMath numeric string</member>
<member><parameter>scale</parameter> is outside the valid range</member>
</simplelist>
</para>
<para>
This function throws a <classname>DivisionByZeroError</classname> exception if <parameter>num2</parameter>
is <literal>0</literal>.
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>bcdivmod</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
bcscale(0);
[$quot, $rem] = bcdivmod('5', '3');
echo $quot; // 1
echo $rem; // 2
[$quot, $rem] = bcdivmod('5', '-3');
echo $quot; // -1
echo $rem; // 2
[$quot, $rem] = bcdivmod('-5', '3');
echo $quot; // -1
echo $rem; // -2
[$quot, $rem] = bcdivmod('-5', '-3');
echo $quot; // 1
echo $rem; // -2
?>
]]>
</programlisting>
</example>
<example>
<title><function>bcdivmod</function> with decimals</title>
<programlisting role="php">
<![CDATA[
<?php
[$quot, $rem] = bcdivmod('5.7', '1.3', 1);
echo $quot; // 4
echo $rem; // 0.5
?>
]]>
</programlisting>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>bcdiv</function></member>
<member><function>bcmod</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
91 changes: 91 additions & 0 deletions reference/bc/functions/bcfloor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.bcfloor" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bcfloor</refname>
<refpurpose>Round arbitrary precision number fractions down</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>bcfloor</methodname>
<methodparam><type>string</type><parameter>num</parameter></methodparam>
</methodsynopsis>
<para>
Returns the next lowest integer value by rounding down
<parameter>num</parameter> if necessary.
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<para>
The value to round.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
num rounded down to the next lowest number as a string.
</para>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>ceil</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
echo bcfloor('4.3'); // '4'
echo bcfloor('9.999'); // '9'
echo bcfloor('-3.14'); // '-4'
?>
]]>
</programlisting>
</example>
</para>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>bcceil</function></member>
<member><function>bcround</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
1 change: 1 addition & 0 deletions reference/bc/functions/bcmod.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ echo bcmod('5.7', '1.3'); // 0.5 as of PHP 7.2.0; 0 previously
<para>
<simplelist>
<member><function>bcdiv</function></member>
<member><function>bcdivmod</function></member>
</simplelist>
</para>
</refsect1>
Expand Down
Loading

0 comments on commit 9110b52

Please sign in to comment.