Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/bcmath: BcMath\Number class #4187

Merged
merged 42 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
32868b6
created common part
SakiTakamachi Nov 29, 2024
78d52d4
created class
SakiTakamachi Nov 29, 2024
0d4e68e
edit book, ini
SakiTakamachi Nov 29, 2024
824d901
Added the class into versions
SakiTakamachi Nov 29, 2024
44f5092
Created construct, serialize, unserialize, toString
SakiTakamachi Nov 29, 2024
df9d597
Created add()
SakiTakamachi Nov 29, 2024
5a711ab
Created sub()
SakiTakamachi Nov 29, 2024
5a2b677
Created div()
SakiTakamachi Nov 29, 2024
64e3458
Created mul()
SakiTakamachi Nov 29, 2024
3ee4949
Created mod()
SakiTakamachi Nov 29, 2024
34f4a6d
Created pow()
SakiTakamachi Nov 29, 2024
e348369
Created divmod()
SakiTakamachi Nov 29, 2024
be8b29d
Created powmod()
SakiTakamachi Nov 29, 2024
8619f4c
Created ceil()
SakiTakamachi Nov 29, 2024
de38dc7
Created floor()
SakiTakamachi Nov 29, 2024
23ef913
Created round()
SakiTakamachi Nov 29, 2024
67ad21f
Created compare()
SakiTakamachi Nov 29, 2024
3a9547b
Created sqrt()
SakiTakamachi Nov 29, 2024
7b51ff8
address a comment
SakiTakamachi Dec 2, 2024
19d38dd
address a comment
SakiTakamachi Dec 2, 2024
88ca28e
address a comment
SakiTakamachi Dec 2, 2024
1917ae3
address a comment
SakiTakamachi Dec 2, 2024
646fe01
address a comment
SakiTakamachi Dec 2, 2024
228cba8
address a comment
SakiTakamachi Dec 2, 2024
3ffc207
address a comment
SakiTakamachi Dec 2, 2024
22792d5
Address comments and more
SakiTakamachi Dec 2, 2024
10e1602
changed "larger" to "greater" and "smaller than" to "less than"
SakiTakamachi Dec 2, 2024
cafb7ff
typo
SakiTakamachi Dec 2, 2024
3a7ed30
Changed the scale param desctiption
SakiTakamachi Dec 2, 2024
cd6f8d7
Deleted unnecessary descriptions
SakiTakamachi Dec 2, 2024
6899586
Avoid nesting includes
SakiTakamachi Dec 2, 2024
c860c08
address a comment
SakiTakamachi Dec 16, 2024
043e7e2
address a comment
SakiTakamachi Dec 16, 2024
5b1228f
address a comment
SakiTakamachi Dec 16, 2024
d2e7031
address a comment
SakiTakamachi Dec 16, 2024
d480231
address a comment
SakiTakamachi Dec 16, 2024
cb0d697
address a comment
SakiTakamachi Dec 16, 2024
6a35375
address a comment
SakiTakamachi Dec 16, 2024
60a76f1
Moved varlistentry of scale parameter to add()
SakiTakamachi Dec 16, 2024
10b03c4
Added a link to "spaceship operator"
SakiTakamachi Dec 16, 2024
6411e68
fixed "+<literal>10" to "<literal>+10"
SakiTakamachi Dec 16, 2024
57d7592
Moded a example code
SakiTakamachi Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions language-snippets.ent
Original file line number Diff line number Diff line change
Expand Up @@ -2155,11 +2155,6 @@ of digits after the decimal place in the result. If omitted, it will default to
globally with the <function>bcscale</function> function, or fallback to <literal>0</literal> if
this has not been set.</para></listitem></varlistentry>'>

<!ENTITY bc.number.scale.description '<varlistentry xmlns="http://docbook.org/ns/docbook"><term>
<parameter>scale</parameter></term><listitem><simpara><parameter>scale</parameter> explicitly
specified for calculation results. If &null;, the <parameter>scale</parameter> of the calculation
result will be set automatically.</simpara></listitem></varlistentry>'>

<!-- CTYPE Notes -->
<!ENTITY note.ctype.parameter.integer '<note xmlns="http://docbook.org/ns/docbook"><para>
If an <type>int</type> between -128 and 255 inclusive is provided, it is interpreted as
Expand Down
10 changes: 9 additions & 1 deletion reference/bc/bcmath/number/add.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
</simpara>
</listitem>
</varlistentry>
&bc.number.scale.description;
<varlistentry>
alfsb marked this conversation as resolved.
Show resolved Hide resolved
<term><parameter>scale</parameter></term>
<listitem>
<simpara>
<parameter>scale</parameter> explicitly specified for calculation results.
If &null;, the <parameter>scale</parameter> of the calculation result will be set automatically.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

Expand Down
2 changes: 1 addition & 1 deletion reference/bc/bcmath/number/compare.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</methodsynopsis>
<simpara>
Compare two arbitrary precision numbers.
This method behaves similar to the spaceship operator.
This method behaves similar to the <link linkend="language.operators.comparison">spaceship operator</link>.
</simpara>
</refsect1>

Expand Down
82 changes: 42 additions & 40 deletions reference/bc/bcmath/number/div.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="bcmath-number.div" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="bcmath-number.div" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>BcMath\Number::div</refname>
<refpurpose>Divides by an arbitrary precision number</refpurpose>
Expand Down Expand Up @@ -28,7 +28,7 @@
</simpara>
</listitem>
</varlistentry>
&bc.number.scale.description;
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
alfsb marked this conversation as resolved.
Show resolved Hide resolved
</variablelist>
</refsect1>

Expand All @@ -50,49 +50,13 @@
</simpara>
<simpara>
Even in indivisible calculations, the <property>BcMath\Number::scale</property> will not always be
+<literal>10</literal>.
<literal>+10</literal>.
A <literal>0</literal> at the end of the result is considered not to need expansion, so the
<property>BcMath\Number::scale</property> is reduced by that amount.
The <property>BcMath\Number::scale</property> will never be less than the
<property>BcMath\Number::scale</property> before expansion.
See also the <link linkend="bcmath-number.div.example.expansion-scale">code example</link>.
</simpara>
<example>
<title>Example of <property>BcMath\Number::scale</property> of result object</title>
<programlisting role="php">
<![CDATA[
<?php
var_dump(
new BcMath\Number('0.001')->div('10001'),
new BcMath\Number('0.001')->div('10001', 13),
new BcMath\Number('0.001')->div('100000000000001'),
);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(BcMath\Number)#2 (2) {
["value"]=>
string(13) "0.00000009999"
["scale"]=>
int(11)
}
object(BcMath\Number)#3 (2) {
["value"]=>
string(15) "0.0000000999900"
["scale"]=>
int(13)
}
object(BcMath\Number)#4 (2) {
["value"]=>
string(5) "0.000"
["scale"]=>
int(3)
}
]]>
</screen>
</example>
</refsect1>

<refsect1 role="errors">
Expand Down Expand Up @@ -201,6 +165,44 @@ object(BcMath\Number)#4 (2) {
["scale"]=>
int(2)
}
]]>
</screen>
</example>

<example xml:id="bcmath-number.div.example.expansion-scale">
<title><methodname>BcMath\Number::div</methodname> example of expansioning <property>BcMath\Number::scale</property> of result object</title>
<programlisting role="php">
<![CDATA[
<?php
var_dump(
new BcMath\Number('0.001')->div('10001'),
new BcMath\Number('0.001')->div('10001', 13),
new BcMath\Number('0.001')->div('100000000000001'),
);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(BcMath\Number)#2 (2) {
["value"]=>
string(13) "0.00000009999"
["scale"]=>
int(11)
}
object(BcMath\Number)#3 (2) {
["value"]=>
string(15) "0.0000000999900"
["scale"]=>
int(13)
}
object(BcMath\Number)#4 (2) {
["value"]=>
string(5) "0.000"
["scale"]=>
int(3)
}
]]>
</screen>
</example>
Expand Down
2 changes: 1 addition & 1 deletion reference/bc/bcmath/number/mul.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</simpara>
</listitem>
</varlistentry>
&bc.number.scale.description;
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
</variablelist>
</refsect1>

Expand Down
6 changes: 3 additions & 3 deletions reference/bc/bcmath/number/pow.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="bcmath-number.pow" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="bcmath-number.pow" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>BcMath\Number::pow</refname>
<refpurpose>Raises an arbitrary precision number</refpurpose>
Expand Down Expand Up @@ -30,7 +30,7 @@
</simpara>
</listitem>
</varlistentry>
&bc.number.scale.description;
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
</variablelist>
</refsect1>

Expand Down Expand Up @@ -72,7 +72,7 @@
<simpara>
If an indivisible division occurs due to a negative <parameter>exponent</parameter>, the <property>
BcMath\Number::scale</property> of the result is expanded. Expansion is done only as needed, up to
a maximum of +<literal>10</literal>.
a maximum of <literal>+10</literal>.
This behavior is the same as <methodname>BcMath\Number::div</methodname>, so please see that for details.
</simpara>
</refsect1>
Expand Down
4 changes: 2 additions & 2 deletions reference/bc/bcmath/number/powmod.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="bcmath-number.powmod" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="bcmath-number.powmod" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>BcMath\Number::powmod</refname>
<refpurpose>Raises an arbitrary precision number, reduced by a specified modulus</refpurpose>
Expand Down Expand Up @@ -38,7 +38,7 @@
</simpara>
</listitem>
</varlistentry>
&bc.number.scale.description;
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
</variablelist>
</refsect1>

Expand Down
6 changes: 3 additions & 3 deletions reference/bc/bcmath/number/sqrt.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="bcmath-number.sqrt" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refentry xml:id="bcmath-number.sqrt" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>BcMath\Number::sqrt</refname>
<refpurpose>Gets the square root of an arbitrary precision number</refpurpose>
Expand All @@ -19,7 +19,7 @@
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
&bc.number.scale.description;
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
</variablelist>
</refsect1>

Expand All @@ -32,7 +32,7 @@
When the <property>BcMath\Number::scale</property> of the result object is automatically set,
the <property>BcMath\Number::scale</property> of this object is used. However, in cases such
as indivisible division, the <property>BcMath\Number::scale</property> of the result is expanded.
Expansion is done only as needed, up to a maximum of +<literal>10</literal>.
Expansion is done only as needed, up to a maximum of <literal>+10</literal>.
</simpara>
<simpara>
That is, if the <property>BcMath\Number::scale</property> of this object is <literal>5</literal>,
Expand Down
2 changes: 1 addition & 1 deletion reference/bc/bcmath/number/sub.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</simpara>
</listitem>
</varlistentry>
&bc.number.scale.description;
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('bcmath-number.add')/db:refsect1[@role='parameters']/descendant::db:varlistentry[2])" />
</variablelist>
</refsect1>

Expand Down
Loading