Skip to content

Commit 87f3287

Browse files
SakiTakamachiGirgiasnielsdos
authored
ext/bcmath: Document bcceil(), bcfloor(), bcround() and bcdivmod() (#4132)
Co-authored-by: Gina Peter Banyard <[email protected]> Co-authored-by: Niels Dossche <[email protected]>
1 parent bda37a3 commit 87f3287

File tree

7 files changed

+617
-0
lines changed

7 files changed

+617
-0
lines changed

reference/bc/functions/bcceil.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<refentry xml:id="function.bcceil" xmlns="http://docbook.org/ns/docbook">
4+
<refnamediv>
5+
<refname>bcceil</refname>
6+
<refpurpose>Round up arbitrary precision number</refpurpose>
7+
</refnamediv>
8+
9+
<refsect1 role="description">
10+
&reftitle.description;
11+
<methodsynopsis>
12+
<type>string</type><methodname>bcceil</methodname>
13+
<methodparam><type>string</type><parameter>num</parameter></methodparam>
14+
</methodsynopsis>
15+
<simpara>
16+
Returns the next highest integer value by rounding up
17+
<parameter>num</parameter> if necessary.
18+
</simpara>
19+
</refsect1>
20+
21+
<refsect1 role="parameters">
22+
&reftitle.parameters;
23+
<variablelist>
24+
<varlistentry>
25+
<term><parameter>num</parameter></term>
26+
<listitem>
27+
<simpara>
28+
The value to round.
29+
</simpara>
30+
</listitem>
31+
</varlistentry>
32+
</variablelist>
33+
</refsect1>
34+
35+
<refsect1 role="returnvalues">
36+
&reftitle.returnvalues;
37+
<simpara>
38+
Returns a numeric string representing <parameter>num</parameter> rounded up to the nearest integer.
39+
</simpara>
40+
</refsect1>
41+
42+
<refsect1 role="examples">
43+
&reftitle.examples;
44+
<example>
45+
<title><function>bcceil</function> example</title>
46+
<programlisting role="php">
47+
<![CDATA[
48+
<?php
49+
var_dump(bcceil('4.3'));
50+
var_dump(bcceil('9.999'));
51+
var_dump(bcceil('-3.14'));
52+
?>
53+
]]>
54+
</programlisting>
55+
&example.outputs;
56+
<screen role="php">
57+
<![CDATA[
58+
string(1) "5"
59+
string(2) "10"
60+
string(2) "-3"
61+
]]>
62+
</screen>
63+
</example>
64+
</refsect1>
65+
66+
<refsect1 role="seealso">
67+
&reftitle.seealso;
68+
<simplelist>
69+
<member><function>bcfloor</function></member>
70+
<member><function>bcround</function></member>
71+
</simplelist>
72+
</refsect1>
73+
</refentry>
74+
<!-- Keep this comment at the end of the file
75+
Local variables:
76+
mode: sgml
77+
sgml-omittag:t
78+
sgml-shorttag:t
79+
sgml-minimize-attributes:nil
80+
sgml-always-quote-attributes:t
81+
sgml-indent-step:1
82+
sgml-indent-data:t
83+
indent-tabs-mode:nil
84+
sgml-parent-document:nil
85+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
86+
sgml-exposed-tags:nil
87+
sgml-local-catalogs:nil
88+
sgml-local-ecat-files:nil
89+
End:
90+
vim600: syn=xml fen fdm=syntax fdl=2 si
91+
vim: et tw=78 syn=sgml
92+
vi: ts=1 sw=1
93+
-->

reference/bc/functions/bcdiv.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ echo bcdiv('105', '6.55957', 3); // 16.007
115115
&reftitle.seealso;
116116
<para>
117117
<simplelist>
118+
<member><function>bcdivmod</function></member>
119+
<member><function>bcmod</function></member>
118120
<member><function>bcmul</function></member>
119121
</simplelist>
120122
</para>

reference/bc/functions/bcdivmod.xml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<refentry xml:id="function.bcdivmod" xmlns="http://docbook.org/ns/docbook">
4+
<refnamediv>
5+
<refname>bcdivmod</refname>
6+
<refpurpose>Get the quotient and modulus of an arbitrary precision number</refpurpose>
7+
</refnamediv>
8+
9+
<refsect1 role="description">
10+
&reftitle.description;
11+
<methodsynopsis>
12+
<type>string</type><methodname>bcdivmod</methodname>
13+
<methodparam><type>string</type><parameter>num1</parameter></methodparam>
14+
<methodparam><type>string</type><parameter>num2</parameter></methodparam>
15+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>scale</parameter><initializer>&null;</initializer></methodparam>
16+
</methodsynopsis>
17+
<simpara>
18+
Get the quotient and remainder of dividing <parameter>num1</parameter> by
19+
<parameter>num2</parameter>.
20+
</simpara>
21+
</refsect1>
22+
23+
<refsect1 role="parameters">
24+
&reftitle.parameters;
25+
<variablelist>
26+
<varlistentry>
27+
<term><parameter>num1</parameter></term>
28+
<listitem>
29+
<simpara>
30+
The dividend, as a string.
31+
</simpara>
32+
</listitem>
33+
</varlistentry>
34+
<varlistentry>
35+
<term><parameter>num2</parameter></term>
36+
<listitem>
37+
<simpara>
38+
The divisor, as a string.
39+
</simpara>
40+
</listitem>
41+
</varlistentry>
42+
&bc.scale.description;
43+
</variablelist>
44+
</refsect1>
45+
46+
<refsect1 role="returnvalues">
47+
&reftitle.returnvalues;
48+
<simpara>
49+
Returns an indexed <type>array</type> where the first element is the quotient as a <type>string</type>
50+
and the second element is the remainder as a <type>string</type>.
51+
</simpara>
52+
</refsect1>
53+
54+
<refsect1 role="errors">
55+
&reftitle.errors;
56+
<para>
57+
This function throws a <exceptionname>ValueError</exceptionname> in the following cases:
58+
<simplelist>
59+
<member><parameter>num1</parameter> or <parameter>num2</parameter> is not a well-formed BCMath numeric string</member>
60+
<member><parameter>scale</parameter> is outside the valid range</member>
61+
</simplelist>
62+
</para>
63+
<simpara>
64+
This function throws a <exceptionname>DivisionByZeroError</exceptionname> exception if <parameter>num2</parameter>
65+
is <literal>0</literal>.
66+
</simpara>
67+
</refsect1>
68+
69+
<refsect1 role="examples">
70+
&reftitle.examples;
71+
<example>
72+
<title><function>bcdivmod</function> example</title>
73+
<programlisting role="php">
74+
<![CDATA[
75+
<?php
76+
bcscale(0);
77+
78+
[$quot, $rem] = bcdivmod('5', '3');
79+
echo $quot; // 1
80+
echo $rem; // 2
81+
82+
[$quot, $rem] = bcdivmod('5', '-3');
83+
echo $quot; // -1
84+
echo $rem; // 2
85+
86+
[$quot, $rem] = bcdivmod('-5', '3');
87+
echo $quot; // -1
88+
echo $rem; // -2
89+
90+
[$quot, $rem] = bcdivmod('-5', '-3');
91+
echo $quot; // 1
92+
echo $rem; // -2
93+
?>
94+
]]>
95+
</programlisting>
96+
</example>
97+
<example>
98+
<title><function>bcdivmod</function> with decimals</title>
99+
<programlisting role="php">
100+
<![CDATA[
101+
<?php
102+
[$quot, $rem] = bcdivmod('5.7', '1.3', 1);
103+
echo $quot; // 4
104+
echo $rem; // 0.5
105+
?>
106+
]]>
107+
</programlisting>
108+
</example>
109+
</refsect1>
110+
111+
<refsect1 role="seealso">
112+
&reftitle.seealso;
113+
<simplelist>
114+
<member><function>bcdiv</function></member>
115+
<member><function>bcmod</function></member>
116+
</simplelist>
117+
</refsect1>
118+
</refentry>
119+
<!-- Keep this comment at the end of the file
120+
Local variables:
121+
mode: sgml
122+
sgml-omittag:t
123+
sgml-shorttag:t
124+
sgml-minimize-attributes:nil
125+
sgml-always-quote-attributes:t
126+
sgml-indent-step:1
127+
sgml-indent-data:t
128+
indent-tabs-mode:nil
129+
sgml-parent-document:nil
130+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
131+
sgml-exposed-tags:nil
132+
sgml-local-catalogs:nil
133+
sgml-local-ecat-files:nil
134+
End:
135+
vim600: syn=xml fen fdm=syntax fdl=2 si
136+
vim: et tw=78 syn=sgml
137+
vi: ts=1 sw=1
138+
-->

reference/bc/functions/bcfloor.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<refentry xml:id="function.bcfloor" xmlns="http://docbook.org/ns/docbook">
4+
<refnamediv>
5+
<refname>bcfloor</refname>
6+
<refpurpose>Round down arbitrary precision number</refpurpose>
7+
</refnamediv>
8+
9+
<refsect1 role="description">
10+
&reftitle.description;
11+
<methodsynopsis>
12+
<type>string</type><methodname>bcfloor</methodname>
13+
<methodparam><type>string</type><parameter>num</parameter></methodparam>
14+
</methodsynopsis>
15+
<simpara>
16+
Returns the next lowest integer value by rounding down
17+
<parameter>num</parameter> if necessary.
18+
</simpara>
19+
</refsect1>
20+
21+
<refsect1 role="parameters">
22+
&reftitle.parameters;
23+
<variablelist>
24+
<varlistentry>
25+
<term><parameter>num</parameter></term>
26+
<listitem>
27+
<simpara>
28+
The value to round.
29+
</simpara>
30+
</listitem>
31+
</varlistentry>
32+
</variablelist>
33+
</refsect1>
34+
35+
<refsect1 role="returnvalues">
36+
&reftitle.returnvalues;
37+
<simpara>
38+
Returns a numeric string representing <parameter>num</parameter> rounded down to the nearest integer.
39+
</simpara>
40+
</refsect1>
41+
42+
<refsect1 role="examples">
43+
&reftitle.examples;
44+
<example>
45+
<title><function>bcfloor</function> example</title>
46+
<programlisting role="php">
47+
<![CDATA[
48+
<?php
49+
var_dump(bcfloor('4.3'));
50+
var_dump(bcfloor('9.999'));
51+
var_dump(bcfloor('-3.14'));
52+
?>
53+
]]>
54+
</programlisting>
55+
&example.outputs;
56+
<screen role="php">
57+
<![CDATA[
58+
string(1) "4"
59+
string(1) "9"
60+
string(2) "-4"
61+
]]>
62+
</screen>
63+
</example>
64+
</refsect1>
65+
66+
<refsect1 role="seealso">
67+
&reftitle.seealso;
68+
<simplelist>
69+
<member><function>bcceil</function></member>
70+
<member><function>bcround</function></member>
71+
</simplelist>
72+
</refsect1>
73+
</refentry>
74+
<!-- Keep this comment at the end of the file
75+
Local variables:
76+
mode: sgml
77+
sgml-omittag:t
78+
sgml-shorttag:t
79+
sgml-minimize-attributes:nil
80+
sgml-always-quote-attributes:t
81+
sgml-indent-step:1
82+
sgml-indent-data:t
83+
indent-tabs-mode:nil
84+
sgml-parent-document:nil
85+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
86+
sgml-exposed-tags:nil
87+
sgml-local-catalogs:nil
88+
sgml-local-ecat-files:nil
89+
End:
90+
vim600: syn=xml fen fdm=syntax fdl=2 si
91+
vim: et tw=78 syn=sgml
92+
vi: ts=1 sw=1
93+
-->

reference/bc/functions/bcmod.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ echo bcmod('5.7', '1.3'); // 0.5 as of PHP 7.2.0; 0 previously
146146
<para>
147147
<simplelist>
148148
<member><function>bcdiv</function></member>
149+
<member><function>bcdivmod</function></member>
149150
</simplelist>
150151
</para>
151152
</refsect1>

0 commit comments

Comments
 (0)