From 32868b63a5409273f81a03173b95cc048f545b69 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 10:58:05 +0900 Subject: [PATCH 01/42] created common part --- language-snippets.ent | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/language-snippets.ent b/language-snippets.ent index fcf2afe88160..db3f00090fa7 100644 --- a/language-snippets.ent +++ b/language-snippets.ent @@ -2155,6 +2155,11 @@ of digits after the decimal place in the result. If omitted, it will default to globally with the bcscale function, or fallback to 0 if this has not been set.'> + +scalescale explicitly +specified for calculation results. If &null;, the scale of the calculation +result will be set automatically.'> + If an int between -128 and 255 inclusive is provided, it is interpreted as From 78d52d47e0cac1854734af165718d77392d8003f Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 10:58:29 +0900 Subject: [PATCH 02/42] created class --- reference/bc/bcmath.number.xml | 112 +++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 reference/bc/bcmath.number.xml diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml new file mode 100644 index 000000000000..76a51fdf1ac2 --- /dev/null +++ b/reference/bc/bcmath.number.xml @@ -0,0 +1,112 @@ + + + + + The BcMath\Number class + BcMath\Number + + +
+ &reftitle.intro; + + A class for an arbitrary precision number. These objects support overloaded + arithmetic and + comparison operators. + + + + This class is not affected by bcmath.scale in &php.ini;. + + + + + For more information about calculations with operators, see the documentation + for the methods that correspond to the operators. + + +
+ +
+ &reftitle.classsynopsis; + + + + final + readonly + BcMath\Number + + + + implements + Stringable + + + &Properties; + + public + string + value + + + public + int + scale + + + &Methods; + + + + + + + +
+ +
+ &reftitle.properties; + + + value + + + A string representation of an arbitrary precision number. + + + + + scale + + + The scale value currently set on the object. + + + + +
+ +
+ + &reference.bc.bcmath.entities.number; + +
+ From 0d4e68eede1dc460fb5d382c310b3dad9e88d17f Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 10:58:49 +0900 Subject: [PATCH 03/42] edit book, ini --- reference/bc/book.xml | 1 + reference/bc/ini.xml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/reference/bc/book.xml b/reference/bc/book.xml index 6ccda4651a1c..a59db0da29e8 100644 --- a/reference/bc/book.xml +++ b/reference/bc/book.xml @@ -48,6 +48,7 @@ echo bcsub($num1, $num2, 1); // => '0.0' &reference.bc.setup; &reference.bc.reference; + &reference.bc.bcmath.number; diff --git a/reference/bc/ini.xml b/reference/bc/ini.xml index 95764b6229d5..7605048ad064 100644 --- a/reference/bc/ini.xml +++ b/reference/bc/ini.xml @@ -42,6 +42,9 @@ Number of decimal digits for all bcmath functions. See also bcscale.
+ + BcMath\Number is not affected by this setting. + From 824d90168a3016ade450b16bf815233882530933 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 10:59:07 +0900 Subject: [PATCH 04/42] Added the class into versions --- reference/bc/versions.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reference/bc/versions.xml b/reference/bc/versions.xml index 5a85d801a5e6..70f44d9508e2 100644 --- a/reference/bc/versions.xml +++ b/reference/bc/versions.xml @@ -18,6 +18,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/reference/bc/bcmath/number/serialize.xml b/reference/bc/bcmath/number/serialize.xml new file mode 100644 index 000000000000..b6ce00bc1709 --- /dev/null +++ b/reference/bc/bcmath/number/serialize.xml @@ -0,0 +1,51 @@ + + + + BcMath\Number::__serialize + Serializes a BcMath\Number object + + + + &reftitle.description; + + public arrayBcMath\Number::__serialize + + + + Serializes this object. + + + + + &reftitle.parameters; + &no.function.parameters; + + + &reftitle.seealso; + + BcMath\Number::__construct + BcMath\Number::__unserialize + + + + + diff --git a/reference/bc/bcmath/number/tostring.xml b/reference/bc/bcmath/number/tostring.xml new file mode 100644 index 000000000000..091d4a5f817b --- /dev/null +++ b/reference/bc/bcmath/number/tostring.xml @@ -0,0 +1,49 @@ + + + + BcMath\Number::__toString + Converts BcMath\Number to string + + + + &reftitle.description; + + public stringBcMath\Number::__toString + + + + Converts BcMath\Number to string. + + + + + &reftitle.parameters; + &no.function.parameters; + + + &reftitle.returnvalues; + + Returns BcMath\Number::value as a string. + + + + diff --git a/reference/bc/bcmath/number/unserialize.xml b/reference/bc/bcmath/number/unserialize.xml new file mode 100644 index 000000000000..33504505bae2 --- /dev/null +++ b/reference/bc/bcmath/number/unserialize.xml @@ -0,0 +1,68 @@ + + + + BcMath\Number::__unserialize + Deserializes a data parameter into a BcMath\Number object + + + + &reftitle.description; + + public voidBcMath\Number::__unserialize + arraydata + + + Deserializes a data parameter into a BcMath\Number object. + + + + + &reftitle.parameters; + + + data + + + The serialized data parameter as an associative array + + + + + + + + &reftitle.errors; + + This method throws a ValueError if invalid serialized data is passed. + + + + + &reftitle.seealso; + + BcMath\Number::__construct + BcMath\Number::serialize + + + + + From df9d5972a52d640cefb096bacbe11f7f95d1b7b5 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:00:13 +0900 Subject: [PATCH 06/42] Created add() --- reference/bc/bcmath/number/add.xml | 295 +++++++++++++++++++++++++++++ reference/bc/functions/bcadd.xml | 1 + 2 files changed, 296 insertions(+) create mode 100644 reference/bc/bcmath/number/add.xml diff --git a/reference/bc/bcmath/number/add.xml b/reference/bc/bcmath/number/add.xml new file mode 100644 index 000000000000..7858118d247f --- /dev/null +++ b/reference/bc/bcmath/number/add.xml @@ -0,0 +1,295 @@ + + + + BcMath\Number::add + Adds an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::add + BcMath\Numberstringintnum + intnullscale&null; + + + Adds this object and num. + + + + + &reftitle.parameters; + + + num + + + The value to add. + + + + &bc.number.scale.description; + + + + + &reftitle.returnvalues; + + Returns the result of addition as a new BcMath\Number object. + + + The same is true for calculations using operators that correspond to this method. + + + + + &reftitle.errors; + + This method throws a ValueError in the following cases: + + num is string and not a well-formed BCMath numeric string + scale is outside the valid range + + + + When using the operator, throw a ValueError if one of the operands + is string and not a well-formed BCMath numeric string. + + + + + Auto scale + + When the BcMath\Number::scale of the result object is automatically set, + the larger BcMath\Number::scale of the two numbers used for addition is used. + + + That is, if the BcMath\Number::scales of two values are 2 + and 5 respectively, the BcMath\Number::scale of the result + will be 5. + + + If either of the two values is a string, the BcMath\Number::scale + of the string value is automatically obtained. For int, scale + is treated as 0. + + + + + &reftitle.examples; + + <methodname>BcMath\Number::add</methodname> example when <parameter>scale</parameter> is not specified + +add(new BcMath\Number('2.34567')); +$ret2 = $number->add('-3.456'); +$ret3 = $number->add(7); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(7) "3.57967" + ["scale"]=> + int(5) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(6) "-2.222" + ["scale"]=> + int(3) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(5) "8.234" + ["scale"]=> + int(3) +} +]]> + + + + + <methodname>BcMath\Number::add</methodname> example of explicitly specifying <parameter>scale</parameter> + +add(new BcMath\Number('2.34567'), 1); +$ret2 = $number->add('-3.456', 10); +$ret3 = $number->add(7, 0); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(3) "3.5" + ["scale"]=> + int(1) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(13) "-2.2220000000" + ["scale"]=> + int(10) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "8" + ["scale"]=> + int(0) +} +]]> + + + + + + Operator Overload + + BcMath\Number can perform addition using operators. The calculation with + the operator behaves the same as when the method argument scale is &null;. + + + Example of addition using operators + + +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(7) "3.57967" + ["scale"]=> + int(5) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(8) "-2.22278" + ["scale"]=> + int(5) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(5) "8.234" + ["scale"]=> + int(3) +} +]]> + + + + + Examples of increment and shorthand addition using operators + + +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(5) "3.579" + ["scale"]=> + int(3) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(5) "2.234" + ["scale"]=> + int(3) +} +]]> + + + + + + &reftitle.seealso; + + bcadd + BcMath\Number::sub + + + + + diff --git a/reference/bc/functions/bcadd.xml b/reference/bc/functions/bcadd.xml index bf94baeb4630..481853f307f5 100644 --- a/reference/bc/functions/bcadd.xml +++ b/reference/bc/functions/bcadd.xml @@ -99,6 +99,7 @@ echo bcadd($a, $b, 4); // 6.2340 bcsub + BcMath\Number::add From 5a711ab71b4cdedc62109365e37ed3c9fedbf89c Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:00:28 +0900 Subject: [PATCH 07/42] Created sub() --- reference/bc/bcmath/number/sub.xml | 278 +++++++++++++++++++++++++++++ reference/bc/functions/bcsub.xml | 1 + 2 files changed, 279 insertions(+) create mode 100644 reference/bc/bcmath/number/sub.xml diff --git a/reference/bc/bcmath/number/sub.xml b/reference/bc/bcmath/number/sub.xml new file mode 100644 index 000000000000..34b5470482de --- /dev/null +++ b/reference/bc/bcmath/number/sub.xml @@ -0,0 +1,278 @@ + + + + BcMath\Number::sub + Subtracts an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::sub + BcMath\Numberstringintnum + intnullscale&null; + + + Subtracts num from this object. + + + + + &reftitle.parameters; + + + num + + + The value to subtract. + + + + &bc.number.scale.description; + + + + + &reftitle.returnvalues; + + Returns the result of subtraction as a new BcMath\Number object. + + + + + + + + + + + + + When the BcMath\Number::scale of the result object is automatically set, + the larger BcMath\Number::scale of the two numbers used for subtraction is used. + + + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::sub</methodname> example when <parameter>scale</parameter> is not specified + +sub(new BcMath\Number('2.34567')); +$ret2 = $number->sub('-3.456'); +$ret3 = $number->sub(7); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(8) "-1.11167" + ["scale"]=> + int(5) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(5) "4.690" + ["scale"]=> + int(3) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(6) "-5.766" + ["scale"]=> + int(3) +} +]]> + + + + + <methodname>BcMath\Number::sub</methodname> example of explicitly specifying <parameter>scale</parameter> + +sub(new BcMath\Number('2.34567'), 1); +$ret2 = $number->sub('-3.456', 10); +$ret3 = $number->sub(7, 0); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(4) "-1.1" + ["scale"]=> + int(1) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(12) "4.6900000000" + ["scale"]=> + int(10) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(2) "-5" + ["scale"]=> + int(0) +} +]]> + + + + + + + + + BcMath\Number can perform subtraction using operators. The calculation with + the operator behaves the same as when the method argument scale is &null;. + + + Example of subtraction using operators + + +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(8) "-1.11167" + ["scale"]=> + int(5) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(7) "4.69078" + ["scale"]=> + int(5) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(6) "-5.766" + ["scale"]=> + int(3) +} +]]> + + + + + Examples of decrement and shorthand subtraction using operators + + +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(6) "-1.111" + ["scale"]=> + int(3) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(5) "0.234" + ["scale"]=> + int(3) +} +]]> + + + + + + &reftitle.seealso; + + bcsub + BcMath\Number::add + + + + + diff --git a/reference/bc/functions/bcsub.xml b/reference/bc/functions/bcsub.xml index ecc777421020..2e170eb4e0a3 100644 --- a/reference/bc/functions/bcsub.xml +++ b/reference/bc/functions/bcsub.xml @@ -99,6 +99,7 @@ echo bcsub($a, $b, 4); // -3.7660 bcadd + BcMath\Number::sub From 5a2b6777c812fab692793e303439dc31cc485179 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:00:47 +0900 Subject: [PATCH 08/42] Created div() --- reference/bc/bcmath/number/div.xml | 348 +++++++++++++++++++++++++++++ reference/bc/functions/bcdiv.xml | 1 + 2 files changed, 349 insertions(+) create mode 100644 reference/bc/bcmath/number/div.xml diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml new file mode 100644 index 000000000000..b264910f1ed0 --- /dev/null +++ b/reference/bc/bcmath/number/div.xml @@ -0,0 +1,348 @@ + + + + BcMath\Number::div + Divides by an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::div + BcMath\Numberstringintnum + intnullscale&null; + + + Divides this object by num. + + + + + &reftitle.parameters; + + + num + + + The divisor. + + + + &bc.number.scale.description; + + + + + &reftitle.returnvalues; + + Returns the result of division as a new BcMath\Number object. + + + + + + + &reftitle.errors; + + This method throws a ValueError in the following cases: + + num is string and not a well-formed BCMath numeric string + scale is outside the valid range + BcMath\Number::scale of the result object is outside the valid range + + + + This method throws a DivisionByZeroError exception if + num is 0. + + + When using the operator, throw a ValueError in the following cases: + + One of the operands is string and not a well-formed BCMath numeric string + BcMath\Number::scale of the result object is outside the valid range + + + + When using the operator, throw a DivisionByZeroError exception if + divisor is 0. + + + + + + + + When the BcMath\Number::scale of the result object is automatically set, + the BcMath\Number::scale of the dividend is used. However, in cases such + as indivisible division, the BcMath\Number::scale of the result is expanded. + Expansion is done only as needed, up to a maximum of +10. + + + That is, if the BcMath\Number::scale of the dividend is 5, + the BcMath\Number::scale of the result is between 5 and + 15. + + + Even in indivisible calculations, the BcMath\Number::scale will not always be + +10. + A 0 at the end of the result is considered not to need expansion, so the + BcMath\Number::scale is reduced by that amount. + The BcMath\Number::scale will never be smaller than the BcMath\Number::scale + before expansion. + + + Example of <property>BcMath\Number::scale</property> od result object + +div('10001'), + new BcMath\Number('0.001')->div('10001', 13), + new BcMath\Number('0.001')->div('100000000000001'), +); +?> +]]> + + &example.outputs; + + + 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) +} +]]> + + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::div</methodname> example when <parameter>scale</parameter> is not specified + +div(new BcMath\Number('2.000')); +$ret2 = $number->div('-3'); +$ret3 = $number->div(32); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "0.002" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(5) "0.001" + ["scale"]=> + int(3) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(16) "-0.0006666666666" + ["scale"]=> + int(13) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(9) "0.0000625" + ["scale"]=> + int(7) +} +]]> + + + + + <methodname>BcMath\Number::div</methodname> example of explicitly specifying <parameter>scale</parameter> + +div(new BcMath\Number('2.000'), 15); +$ret2 = $number->div('-3', 5); +$ret3 = $number->div(32, 2); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "0.002" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(17) "0.001000000000000" + ["scale"]=> + int(15) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(8) "-0.00066" + ["scale"]=> + int(5) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(4) "0.00" + ["scale"]=> + int(2) +} +]]> + + + + + + + + + BcMath\Number can perform division using operators. The calculation with + the operator behaves the same as when the method argument scale is &null;. + + + Example of division using operators + + +]]> + + &example.outputs; + + + string(5) "0.002" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(5) "0.001" + ["scale"]=> + int(3) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(16) "-0.0006666666666" + ["scale"]=> + int(13) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(9) "0.0000625" + ["scale"]=> + int(7) +} +]]> + + + + + Examples of shorthand division using operators + + +]]> + + &example.outputs; + + + string(1) "3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(3) "1.5" + ["scale"]=> + int(1) +} +]]> + + + + + + &reftitle.seealso; + + bcdiv + BcMath\Number::divmod + BcMath\Number::mod + BcMath\Number::sqrt + BcMath\Number::pow + BcMath\Number::mul + + + + + diff --git a/reference/bc/functions/bcdiv.xml b/reference/bc/functions/bcdiv.xml index 0abfdbe95e99..0195b66fea57 100644 --- a/reference/bc/functions/bcdiv.xml +++ b/reference/bc/functions/bcdiv.xml @@ -118,6 +118,7 @@ echo bcdiv('105', '6.55957', 3); // 16.007 bcdivmod bcmod bcmul + BcMath\Number::div From 64e3458a1d3a8cb56c9969f69b7119ff474790d9 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:00:57 +0900 Subject: [PATCH 09/42] Created mul() --- reference/bc/bcmath/number/mul.xml | 280 +++++++++++++++++++++++++++++ reference/bc/functions/bcmul.xml | 1 + 2 files changed, 281 insertions(+) create mode 100644 reference/bc/bcmath/number/mul.xml diff --git a/reference/bc/bcmath/number/mul.xml b/reference/bc/bcmath/number/mul.xml new file mode 100644 index 000000000000..8cd3a3d1cb9d --- /dev/null +++ b/reference/bc/bcmath/number/mul.xml @@ -0,0 +1,280 @@ + + + + BcMath\Number::mul + Multiplies an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::mul + BcMath\Numberstringintnum + intnullscale&null; + + + Multiplies this object by num. + + + + + &reftitle.parameters; + + + num + + + The multiplier. + + + + &bc.number.scale.description; + + + + + &reftitle.returnvalues; + + Returns the result of multiplication as a new BcMath\Number object. + + + + + + + &reftitle.errors; + + + + + + + + + + + When the BcMath\Number::scale of the result object is automatically set, + the sum of the BcMath\Number::scales of the two values used for multiplication is used. + + + That is, if the BcMath\Number::scales of two values are 2 + and 5 respectively, the BcMath\Number::scale of the result + will be 7. + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::mul</methodname> example when <parameter>scale</parameter> is not specified + +mul(new BcMath\Number('2.3456')); +$ret2 = $number->mul('-3.4'); +$ret3 = $number->mul(7); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(9) "2.8944704" + ["scale"]=> + int(7) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(7) "-4.1956" + ["scale"]=> + int(4) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(5) "8.638" + ["scale"]=> + int(3) +} +]]> + + + + + <methodname>BcMath\Number::mul</methodname> example of explicitly specifying <parameter>scale</parameter> + +mul(new BcMath\Number('2.3456'), 1); +$ret2 = $number->mul('-3.4', 10); +$ret3 = $number->mul(7, 0); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(3) "2.8" + ["scale"]=> + int(1) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(13) "-4.1956000000" + ["scale"]=> + int(10) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "8" + ["scale"]=> + int(0) +} +]]> + + + + + + + + + BcMath\Number can perform multiplication using operators. The calculation with + the operator behaves the same as when the method argument scale is &null;. + + + Example of multiplication using operators + + +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(9) "2.8944704" + ["scale"]=> + int(7) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(7) "-4.1956" + ["scale"]=> + int(4) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(5) "8.638" + ["scale"]=> + int(3) +} +]]> + + + + + Examples of shorthand multiplication using operators + + +]]> + + &example.outputs; + + + string(5) "1.234" + ["scale"]=> + int(3) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(8) "2.893730" + ["scale"]=> + int(6) +} +]]> + + + + + + &reftitle.seealso; + + bcmul + BcMath\Number::div + BcMath\Number::pow + BcMath\Number::powmod + + + + + diff --git a/reference/bc/functions/bcmul.xml b/reference/bc/functions/bcmul.xml index d45351230b49..f6af2a7b6099 100644 --- a/reference/bc/functions/bcmul.xml +++ b/reference/bc/functions/bcmul.xml @@ -123,6 +123,7 @@ echo bcmul('5', '2', 2); // prints "10", not "10.00" bcdiv + BcMath\Number::mul From 3ee4949fe0cae5cd5a55a3002be71a219dfe615b Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:01:05 +0900 Subject: [PATCH 10/42] Created mod() --- reference/bc/bcmath/number/mod.xml | 271 +++++++++++++++++++++++++++++ reference/bc/functions/bcmod.xml | 1 + 2 files changed, 272 insertions(+) create mode 100644 reference/bc/bcmath/number/mod.xml diff --git a/reference/bc/bcmath/number/mod.xml b/reference/bc/bcmath/number/mod.xml new file mode 100644 index 000000000000..64c85a9de583 --- /dev/null +++ b/reference/bc/bcmath/number/mod.xml @@ -0,0 +1,271 @@ + + + + BcMath\Number::mod + Gets the modulus of an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::mod + BcMath\Numberstringintnum + intnullscale&null; + + + Gets the remainder of dividing this object by num. + Unless num is 0, the result has the same sign + as this object. + + + + + + + + &reftitle.returnvalues; + + Returns the modulus as a new BcMath\Number object. + + + + + + + &reftitle.errors; + + + + + + + + + + + + + + + When the BcMath\Number::scale of the result object is automatically set, + the larger BcMath\Number::scale of the two numbers used for modulus operation is used. + + + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::mod</methodname> example when <parameter>scale</parameter> is not specified + +mod(new BcMath\Number('2.22')); +$ret2 = $number->mod('8.3'); +$ret3 = $number->mod(-5); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(3) "8.3" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(4) "1.64" + ["scale"]=> + int(2) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(3) "0.0" + ["scale"]=> + int(1) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "3.3" + ["scale"]=> + int(1) +} +]]> + + + + + <methodname>BcMath\Number::mod</methodname> example of explicitly specifying <parameter>scale</parameter> + +mod(new BcMath\Number('2.22'), 1); +$ret2 = $number->mod('8.3', 3); +$ret3 = $number->mod(-5, 0); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(3) "8.3" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(3) "1.6" + ["scale"]=> + int(1) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(5) "0.000" + ["scale"]=> + int(3) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "3" + ["scale"]=> + int(0) +} +]]> + + + + + + + + + BcMath\Number can perform modulus operation using operators. The calculation with + the operator behaves the same as when the method argument scale is &null;. + + + Example of modulus operation using operators + + +]]> + + &example.outputs; + + + string(4) "-7.1" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(5) "-0.66" + ["scale"]=> + int(2) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(3) "0.0" + ["scale"]=> + int(1) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(4) "-1.1" + ["scale"]=> + int(1) +} +]]> + + + + + Examples of shorthand modulus operation using operators + + +]]> + + &example.outputs; + + + string(1) "3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +]]> + + + + + + &reftitle.seealso; + + bcmod + BcMath\Number::div + BcMath\Number::divmod + BcMath\Number::powmod + + + + + diff --git a/reference/bc/functions/bcmod.xml b/reference/bc/functions/bcmod.xml index 2f5135d1772f..72618795510b 100644 --- a/reference/bc/functions/bcmod.xml +++ b/reference/bc/functions/bcmod.xml @@ -147,6 +147,7 @@ echo bcmod('5.7', '1.3'); // 0.5 as of PHP 7.2.0; 0 previously bcdiv bcdivmod + BcMath\Number::mod From 34f4a6dc4d94b52a32ae67ffc65fcfbad58e0afa Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:01:16 +0900 Subject: [PATCH 11/42] Created pow() --- reference/bc/bcmath/number/pow.xml | 348 +++++++++++++++++++++++++++++ reference/bc/functions/bcpow.xml | 1 + 2 files changed, 349 insertions(+) create mode 100644 reference/bc/bcmath/number/pow.xml diff --git a/reference/bc/bcmath/number/pow.xml b/reference/bc/bcmath/number/pow.xml new file mode 100644 index 000000000000..755ae9692c33 --- /dev/null +++ b/reference/bc/bcmath/number/pow.xml @@ -0,0 +1,348 @@ + + + + BcMath\Number::pow + Raises an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::pow + BcMath\Numberstringintexponent + intnullscale&null; + + + Raises this object to the exponent power. + + + + + &reftitle.parameters; + + + exponent + + + The exponent. Must be a value with no fractional part. + The valid range of the exponent is platform specific, but is at least + -2147483648 to 2147483647. + + + + &bc.number.scale.description; + + + + + &reftitle.returnvalues; + + Returns the result of power as a new BcMath\Number object. + + + + + + + &reftitle.errors; + + This method throws a ValueError in the following cases: + + exponent is string and not a well-formed BCMath numeric string + exponent has a fractional part + exponent or scale is outside the valid range + BcMath\Number::scale of the result object is outside the valid range + + + + This method throws a DivisionByZeroError exception if this object's value + is 0 and exponent is a negative value. + + + When using the operator, throws a ValueError in the following cases: + + exponent is string and not a well-formed BCMath numeric string + exponent has a fractional part + exponent is outside the valid range + BcMath\Number::scale of the result object is outside the valid range + + + + When using the operator, throw a DivisionByZeroError exception If the left + operand is 0 and the right operand is a negative value. + + + + + + + + When the BcMath\Number::scale of the result object is automatically set, + depending on the value of exponent, the BcMath\Number::scale + of result will be as follows: + + + + + exponent + BcMath\Number::scale of result + + + + + positive + (BcMath\Number::scale of power base) * (exponent's value) + + + 0 + 0 + + + negative + Between (BcMath\Number::scale of power base) and (BcMath\Number::scale + of power base + 10) + + + + + + + If an indivisible division occurs due to a negative exponent, the + BcMath\Number::scale of the result is expanded. Expansion is done only as needed, up to + a maximum of +10. + This behavior is the same as BcMath\Number::div, so please see that for details. + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::pow</methodname> example when <parameter>scale</parameter> is not specified + +pow(new BcMath\Number('5')); +$ret2 = $number->pow('-1'); +$ret3 = $number->pow(0); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(3) "3.0" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(9) "243.00000" + ["scale"]=> + int(5) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(13) "0.33333333333" + ["scale"]=> + int(11) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +]]> + + + + + <methodname>BcMath\Number::pow</methodname> example of explicitly specifying <parameter>scale</parameter> + +pow(new BcMath\Number('5'), 0); +$ret2 = $number->pow('-1', 2); +$ret3 = $number->pow(0, 10); + +var_dump($number, $ret1, $ret2, $ret3); +?> +]]> + + &example.outputs; + + + string(3) "3.0" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(3) "243" + ["scale"]=> + int(0) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(4) "0.33" + ["scale"]=> + int(2) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(12) "1.0000000000" + ["scale"]=> + int(10) +} +]]> + + + + + + + + + BcMath\Number can perform power using operators. The calculation with + the operator behaves the same as when the method argument scale is &null;. + + + Example of power using operators + + +]]> + + &example.outputs; + + + string(3) "3.0" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(9) "243.00000" + ["scale"]=> + int(5) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(13) "0.33333333333" + ["scale"]=> + int(11) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +]]> + + + + + Examples of shorthand power using operators + + +]]> + + &example.outputs; + + + string(3) "1.2" + ["scale"]=> + int(1) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(4) "1.44" + ["scale"]=> + int(2) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(13) "0.83333333333" + ["scale"]=> + int(11) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +]]> + + + + + + &reftitle.seealso; + + bcpow + BcMath\Number::powmod + BcMath\Number::mul + BcMath\Number::sqrt + BcMath\Number::div + + + + + diff --git a/reference/bc/functions/bcpow.xml b/reference/bc/functions/bcpow.xml index ca3d701cee44..f7bb25b5a92c 100644 --- a/reference/bc/functions/bcpow.xml +++ b/reference/bc/functions/bcpow.xml @@ -151,6 +151,7 @@ echo bcpow('5', '2', 2); // prints "25", not "25.00" bcpowmod bcsqrt + BcMath\Number::pow From e34836906efb121a1e541ab2a5756da304ced1dd Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:01:30 +0900 Subject: [PATCH 12/42] Created divmod() --- reference/bc/bcmath/number/divmod.xml | 235 ++++++++++++++++++++++++++ reference/bc/functions/bcdivmod.xml | 1 + 2 files changed, 236 insertions(+) create mode 100644 reference/bc/bcmath/number/divmod.xml diff --git a/reference/bc/bcmath/number/divmod.xml b/reference/bc/bcmath/number/divmod.xml new file mode 100644 index 000000000000..a4d569cecf83 --- /dev/null +++ b/reference/bc/bcmath/number/divmod.xml @@ -0,0 +1,235 @@ + + + + BcMath\Number::divmod + Gets the quotient and modulus of an arbitrary precision number + + + + &reftitle.description; + + public arrayBcMath\Number::divmod + BcMath\Numberstringintnum + intnullscale&null; + + + Gets the quotient and remainder of dividing this object by num. + + + + + + + + &reftitle.returnvalues; + + Returns an indexed array where the first element is the quotient as a new + BcMath\Number object and the second element is the remainder as a new + BcMath\Number object. + + + The quotient is always an integer value, so BcMath\Number::scale is always 0. + + + + + &reftitle.errors; + + + + + + + + + + + + + + + The quotient is always an integer value, so BcMath\Number::scale of the quotient will + always be 0, regardless of whether explicitly specify scale. + + + If scale is explicitly specified, BcMath\Number::scale of the + remainder will be the specified value. + When the BcMath\Number::scale of the result's remainder object is automatically set, + the larger BcMath\Number::scale of the two numbers used for modulus operation is used. + + + That is, if the BcMath\Number::scales of two values are 2 + and 5 respectively, the BcMath\Number::scale of the remainder + will be 5. + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::divmod</methodname> example when <parameter>scale</parameter> is not specified + +divmod(new BcMath\Number('2.22')); +var_dump($quot, $rem); + +echo PHP_EOL . '8.3 / 8.3' . PHP_EOL; +[$quot, $rem] = new BcMath\Number('8.3')->divmod('8.3'); +var_dump($quot, $rem); + +echo PHP_EOL . '10 / -3' . PHP_EOL; +[$quot, $rem] = new BcMath\Number('10')->divmod(-3); +var_dump($quot, $rem); +?> +]]> + + &example.outputs; + + + string(1) "3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(4) "1.34" + ["scale"]=> + int(2) +} + +8.3 / 8.3 +object(BcMath\Number)#2 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(3) "0.0" + ["scale"]=> + int(1) +} + +10 / -3 +object(BcMath\Number)#3 (2) { + ["value"]=> + string(2) "-3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#1 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +]]> + + + + + <methodname>BcMath\Number::divmod</methodname> example of explicitly specifying <parameter>scale</parameter> + +divmod(new BcMath\Number('2.22'), 1); +var_dump($quot, $rem); + +echo PHP_EOL . '8.3 / 8.3' . PHP_EOL; +[$quot, $rem] = new BcMath\Number('8.3')->divmod('8.3', 4); +var_dump($quot, $rem); + +echo PHP_EOL . '10 / -3' . PHP_EOL; +[$quot, $rem] = new BcMath\Number('10')->divmod(-3, 5); +var_dump($quot, $rem); +?> +]]> + + &example.outputs; + + + string(1) "3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.3" + ["scale"]=> + int(1) +} + +8.3 / 8.3 +object(BcMath\Number)#2 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(6) "0.0000" + ["scale"]=> + int(4) +} + +10 / -3 +object(BcMath\Number)#3 (2) { + ["value"]=> + string(2) "-3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#1 (2) { + ["value"]=> + string(7) "1.00000" + ["scale"]=> + int(5) +} +]]> + + + + + + &reftitle.seealso; + + bcdivmod + BcMath\Number::div + BcMath\Number::mod + + + + + diff --git a/reference/bc/functions/bcdivmod.xml b/reference/bc/functions/bcdivmod.xml index 76cd7c2b7684..840fcf8e7758 100644 --- a/reference/bc/functions/bcdivmod.xml +++ b/reference/bc/functions/bcdivmod.xml @@ -113,6 +113,7 @@ echo $rem; // 0.5 bcdiv bcmod + BcMath\Number::divmod From be8b29d3d95e5457fd2ebc1e172084f87359a9dc Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:01:44 +0900 Subject: [PATCH 13/42] Created powmod() --- reference/bc/bcmath/number/powmod.xml | 202 ++++++++++++++++++++++++++ reference/bc/functions/bcpowmod.xml | 1 + 2 files changed, 203 insertions(+) create mode 100644 reference/bc/bcmath/number/powmod.xml diff --git a/reference/bc/bcmath/number/powmod.xml b/reference/bc/bcmath/number/powmod.xml new file mode 100644 index 000000000000..2c2e9441ebb2 --- /dev/null +++ b/reference/bc/bcmath/number/powmod.xml @@ -0,0 +1,202 @@ + + + + BcMath\Number::powmod + Raises an arbitrary precision number, reduced by a specified modulus + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::powmod + BcMath\Numberstringintexponent + BcMath\Numberstringintmodulus + intnullscale&null; + + + Use the fast-exponentiation method to raise this object to the power + exponent with respect to the modulus + modulus. + + + + + &reftitle.parameters; + + + exponent + + + The exponent, as an non-negative and integral (i.e. the scale has to be zero). + + + + + modulus + + + The modulus, as an integral (i.e. the scale has to be zero). + + + + &bc.number.scale.description; + + + + + &reftitle.returnvalues; + + Returns the result as a new BcMath\Number object. + + + + + &reftitle.errors; + + This method throws a ValueError in the following cases: + + exponent or modulus is string and not + a well-formed BCMath numeric string + This object, exponent or modulus has a fractional part + exponent is a negative value + scale is outside the valid range + + + + This method throws a DivisionByZeroError exception if modulus + is 0. + + + + + + + + When the BcMath\Number::scale of the result object is automatically set, + the BcMath\Number::scale of the result object will always be 0. + + + + + &reftitle.examples; + + <methodname>BcMath\Number::powmod</methodname> example when <parameter>scale</parameter> is not specified + +powmod(new BcMath\Number('3'), 5), + new BcMath\Number('-8')->powmod(new BcMath\Number('3'), 5), + new BcMath\Number('8')->powmod('2', -3), + new BcMath\Number('-8')->powmod(5, 7), +); +?> +]]> + + &example.outputs; + + + string(1) "2" + ["scale"]=> + int(0) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(2) "-2" + ["scale"]=> + int(0) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(1) "1" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(2) "-1" + ["scale"]=> + int(0) +} +]]> + + + + + <methodname>BcMath\Number::powmod</methodname> example of explicitly specifying <parameter>scale</parameter> + +powmod(new BcMath\Number('3'), 5, 1), + new BcMath\Number('-8')->powmod(new BcMath\Number('3'), 5, 2), + new BcMath\Number('8')->powmod('2', -3, 3), + new BcMath\Number('-8')->powmod(5, 7, 4), +); +?> +]]> + + &example.outputs; + + + string(3) "2.0" + ["scale"]=> + int(1) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(5) "-2.00" + ["scale"]=> + int(2) +} +object(BcMath\Number)#2 (2) { + ["value"]=> + string(5) "1.000" + ["scale"]=> + int(3) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(7) "-1.0000" + ["scale"]=> + int(4) +} +]]> + + + + + + &reftitle.seealso; + + bcpowmod + BcMath\Number::pow + BcMath\Number::mod + + + + + diff --git a/reference/bc/functions/bcpowmod.xml b/reference/bc/functions/bcpowmod.xml index 0d173eb0fdff..b8d52c1cac35 100644 --- a/reference/bc/functions/bcpowmod.xml +++ b/reference/bc/functions/bcpowmod.xml @@ -125,6 +125,7 @@ $b = bcmod(bcpow($x, $y), $mod); bcpow bcmod + BcMath\Number::powmod From 8619f4cbb82967f0bbea56f926499ec258ed313b Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:02:00 +0900 Subject: [PATCH 14/42] Created ceil() --- reference/bc/bcmath/number/ceil.xml | 102 ++++++++++++++++++++++++++++ reference/bc/functions/bcceil.xml | 1 + 2 files changed, 103 insertions(+) create mode 100644 reference/bc/bcmath/number/ceil.xml diff --git a/reference/bc/bcmath/number/ceil.xml b/reference/bc/bcmath/number/ceil.xml new file mode 100644 index 000000000000..dcb930b3976c --- /dev/null +++ b/reference/bc/bcmath/number/ceil.xml @@ -0,0 +1,102 @@ + + + + BcMath\Number::ceil + Rounds up an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::ceil + + + + Returns the next highest integer value by rounding up + this object if necessary. + + + + + &reftitle.parameters; + &no.function.parameters; + + + &reftitle.returnvalues; + + Returns the result as a new BcMath\Number object. + The BcMath\Number::scale of the result is always 0. + + + + + &reftitle.examples; + + <methodname>BcMath\Number::ceil</methodname> example + +ceil(); +$num2 = new BcMath\Number('9.999')->ceil(); +$num3 = new BcMath\Number('-3.14')->ceil(); + +var_dump($num1, $num2, $num3); +?> +]]> + + &example.outputs; + + + string(1) "5" + ["scale"]=> + int(0) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(2) "10" + ["scale"]=> + int(0) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(2) "-3" + ["scale"]=> + int(0) +} +]]> + + + + + + &reftitle.seealso; + + bcceil + BcMath\Number::floor + BcMath\Number::round + + + + + diff --git a/reference/bc/functions/bcceil.xml b/reference/bc/functions/bcceil.xml index d2e9be85e986..612f1d29bad0 100644 --- a/reference/bc/functions/bcceil.xml +++ b/reference/bc/functions/bcceil.xml @@ -68,6 +68,7 @@ string(2) "-3" bcfloor bcround + BcMath\Number::ceil From de38dc7ee9a25be60637c31c30cf0f98265efb96 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:02:15 +0900 Subject: [PATCH 15/42] Created floor() --- reference/bc/bcmath/number/floor.xml | 97 ++++++++++++++++++++++++++++ reference/bc/functions/bcfloor.xml | 1 + 2 files changed, 98 insertions(+) create mode 100644 reference/bc/bcmath/number/floor.xml diff --git a/reference/bc/bcmath/number/floor.xml b/reference/bc/bcmath/number/floor.xml new file mode 100644 index 000000000000..4f089cb9f3fe --- /dev/null +++ b/reference/bc/bcmath/number/floor.xml @@ -0,0 +1,97 @@ + + + + BcMath\Number::floor + Rounds down an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::floor + + + + Returns the next highest integer value by rounding down + this object if necessary. + + + + + &reftitle.parameters; + &no.function.parameters; + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::floor</methodname> example + +floor(); +$num2 = new BcMath\Number('9.999')->floor(); +$num3 = new BcMath\Number('-3.14')->floor(); + +var_dump($num1, $num2, $num3); +?> +]]> + + &example.outputs; + + + string(1) "4" + ["scale"]=> + int(0) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(2) "-4" + ["scale"]=> + int(0) +} +]]> + + + + + + &reftitle.seealso; + + bcfloor + BcMath\Number::ceil + BcMath\Number::round + + + + + diff --git a/reference/bc/functions/bcfloor.xml b/reference/bc/functions/bcfloor.xml index 8ed28a46e60b..838c54de3718 100644 --- a/reference/bc/functions/bcfloor.xml +++ b/reference/bc/functions/bcfloor.xml @@ -68,6 +68,7 @@ string(2) "-4" bcceil bcround + BcMath\Number::floor From 23ef913f0cfbc7ff848d3fcd9f8b9bab22cc1abc Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:02:26 +0900 Subject: [PATCH 16/42] Created round() --- reference/bc/bcmath/number/round.xml | 554 +++++++++++++++++++++++++++ reference/bc/functions/bcround.xml | 1 + 2 files changed, 555 insertions(+) create mode 100644 reference/bc/bcmath/number/round.xml diff --git a/reference/bc/bcmath/number/round.xml b/reference/bc/bcmath/number/round.xml new file mode 100644 index 000000000000..6956551596e1 --- /dev/null +++ b/reference/bc/bcmath/number/round.xml @@ -0,0 +1,554 @@ + + + + BcMath\Number::round + Rounds an arbitrary precision number + + + + &reftitle.description; + + public BcMath\NumberBcMath\Number::round + intprecision0 + RoundingModemodeRoundingMode::HalfAwayFromZero + + + Returns the rounded value of this object to + specified precision + (number of digits after the decimal point). + precision can also be negative or zero (default). + + + + + &reftitle.parameters; + + + + + + + + + + &reftitle.returnvalues; + + Returns the result as a new BcMath\Number object. + + + + + &reftitle.examples; + + <methodname>BcMath\Number::round</methodname> example + +round(), + new BcMath\Number('3.5')->round(), + new BcMath\Number('3.6')->round(), + new BcMath\Number('3.6')->round(0), + new BcMath\Number('5.045')->round(2), + new BcMath\Number('5.055')->round(2), + new BcMath\Number('345')->round(-2), + new BcMath\Number('345')->round(-3), + new BcMath\Number('678')->round(-2), + new BcMath\Number('678')->round(-3), +); +?> +]]> + + &example.outputs; + + + string(1) "3" + ["scale"]=> + int(0) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(1) "4" + ["scale"]=> + int(0) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "4" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(1) "4" + ["scale"]=> + int(0) +} +object(BcMath\Number)#6 (2) { + ["value"]=> + string(4) "5.05" + ["scale"]=> + int(2) +} +object(BcMath\Number)#7 (2) { + ["value"]=> + string(4) "5.06" + ["scale"]=> + int(2) +} +object(BcMath\Number)#8 (2) { + ["value"]=> + string(3) "300" + ["scale"]=> + int(0) +} +object(BcMath\Number)#9 (2) { + ["value"]=> + string(1) "0" + ["scale"]=> + int(0) +} +object(BcMath\Number)#10 (2) { + ["value"]=> + string(3) "700" + ["scale"]=> + int(0) +} +object(BcMath\Number)#11 (2) { + ["value"]=> + string(4) "1000" + ["scale"]=> + int(0) +} +]]> + + + + + Example of using <methodname>BcMath\Number::round</methodname> with different <parameter>precision</parameter> values + + +round(3), + $number->round(2), + $number->round(1), + $number->round(0), + $number->round(-1), + $number->round(-2), + $number->round(-3), +); +?> +]]> + + &example.outputs; + + + string(6) "123.45" + ["scale"]=> + int(2) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(6) "123.45" + ["scale"]=> + int(2) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(5) "123.5" + ["scale"]=> + int(1) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(3) "123" + ["scale"]=> + int(0) +} +object(BcMath\Number)#6 (2) { + ["value"]=> + string(3) "120" + ["scale"]=> + int(0) +} +object(BcMath\Number)#7 (2) { + ["value"]=> + string(3) "100" + ["scale"]=> + int(0) +} +object(BcMath\Number)#8 (2) { + ["value"]=> + string(1) "0" + ["scale"]=> + int(0) +} +]]> + + + + + Example of using <methodname>BcMath\Number::round</methodname> with different <parameter>mode</parameter> values + + +round(0, RoundingMode::HalfAwayFromZero), + $number->round(0, RoundingMode::HalfTowardsZero), + $number->round(0, RoundingMode::HalfEven), + $number->round(0, RoundingMode::HalfOdd), + $number->round(0, RoundingMode::TowardsZero), + $number->round(0, RoundingMode::AwayFromZero), + $number->round(0, RoundingMode::NegativeInfinity), + $number->round(0, RoundingMode::PositiveInfinity), +); + +echo PHP_EOL; +echo 'Rounding modes with 8.5' . PHP_EOL; +$number = new BcMath\Number('8.5'); +var_dump( + $number->round(0, RoundingMode::HalfAwayFromZero), + $number->round(0, RoundingMode::HalfTowardsZero), + $number->round(0, RoundingMode::HalfEven), + $number->round(0, RoundingMode::HalfOdd), + $number->round(0, RoundingMode::TowardsZero), + $number->round(0, RoundingMode::AwayFromZero), + $number->round(0, RoundingMode::NegativeInfinity), + $number->round(0, RoundingMode::PositiveInfinity), +); +?> +]]> + + &example.outputs; + + + string(2) "10" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#7 (2) { + ["value"]=> + string(2) "10" + ["scale"]=> + int(0) +} +object(BcMath\Number)#9 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#11 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#13 (2) { + ["value"]=> + string(2) "10" + ["scale"]=> + int(0) +} +object(BcMath\Number)#15 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#17 (2) { + ["value"]=> + string(2) "10" + ["scale"]=> + int(0) +} + +Rounding modes with 8.5 +object(BcMath\Number)#1 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#15 (2) { + ["value"]=> + string(1) "8" + ["scale"]=> + int(0) +} +object(BcMath\Number)#13 (2) { + ["value"]=> + string(1) "8" + ["scale"]=> + int(0) +} +object(BcMath\Number)#11 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#9 (2) { + ["value"]=> + string(1) "8" + ["scale"]=> + int(0) +} +object(BcMath\Number)#7 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(1) "8" + ["scale"]=> + int(0) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(1) "9" + ["scale"]=> + int(0) +} +]]> + + + + + Example of using <methodname>BcMath\Number::round</methodname> with different <parameter>mode</parameter> values + when specifying <parameter>precision</parameter> + + +round(1, RoundingMode::HalfAwayFromZero), + $negative->round(1, RoundingMode::HalfAwayFromZero), +); + +echo PHP_EOL; +echo 'Using RoundingMode::HalfTowardsZero with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::HalfTowardsZero), + $negative->round(1, RoundingMode::HalfTowardsZero), +); + +echo PHP_EOL; +echo 'Using RoundingMode::HalfEven with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::HalfEven), + $negative->round(1, RoundingMode::HalfEven), +); + +echo PHP_EOL; +echo 'Using RoundingMode::HalfOdd with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::HalfOdd), + $negative->round(1, RoundingMode::HalfOdd), +); + +echo PHP_EOL; +echo 'Using RoundingMode::TowardsZero with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::TowardsZero), + $negative->round(1, RoundingMode::TowardsZero), +); + +echo PHP_EOL; +echo 'Using RoundingMode::AwayFromZero with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::AwayFromZero), + $negative->round(1, RoundingMode::AwayFromZero), +); + +echo PHP_EOL; +echo 'Using RoundingMode::NegativeInfinity with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::NegativeInfinity), + $negative->round(1, RoundingMode::NegativeInfinity), +); + +echo PHP_EOL; +echo 'Using RoundingMode::PositiveInfinity with 1 decimal digit precision' . PHP_EOL; +var_dump( + $positive->round(1, RoundingMode::PositiveInfinity), + $negative->round(1, RoundingMode::PositiveInfinity), +); +?> +]]> + + &example.outputs; + + + string(3) "1.6" + ["scale"]=> + int(1) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(4) "-1.6" + ["scale"]=> + int(1) +} + +Using RoundingMode::HalfTowardsZero with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.5" + ["scale"]=> + int(1) +} +object(BcMath\Number)#6 (2) { + ["value"]=> + string(4) "-1.5" + ["scale"]=> + int(1) +} + +Using RoundingMode::HalfEven with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.6" + ["scale"]=> + int(1) +} +object(BcMath\Number)#7 (2) { + ["value"]=> + string(4) "-1.6" + ["scale"]=> + int(1) +} + +Using RoundingMode::HalfOdd with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.5" + ["scale"]=> + int(1) +} +object(BcMath\Number)#8 (2) { + ["value"]=> + string(4) "-1.5" + ["scale"]=> + int(1) +} + +Using RoundingMode::TowardsZero with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.5" + ["scale"]=> + int(1) +} +object(BcMath\Number)#9 (2) { + ["value"]=> + string(4) "-1.5" + ["scale"]=> + int(1) +} + +Using RoundingMode::AwayFromZero with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.6" + ["scale"]=> + int(1) +} +object(BcMath\Number)#10 (2) { + ["value"]=> + string(4) "-1.6" + ["scale"]=> + int(1) +} + +Using RoundingMode::NegativeInfinity with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.5" + ["scale"]=> + int(1) +} +object(BcMath\Number)#11 (2) { + ["value"]=> + string(4) "-1.6" + ["scale"]=> + int(1) +} + +Using RoundingMode::PositiveInfinity with 1 decimal digit precision +object(BcMath\Number)#4 (2) { + ["value"]=> + string(3) "1.6" + ["scale"]=> + int(1) +} +object(BcMath\Number)#12 (2) { + ["value"]=> + string(4) "-1.5" + ["scale"]=> + int(1) +} +]]> + + + + + + &reftitle.seealso; + + bcround + BcMath\Number::ceil + BcMath\Number::floor + + + + + diff --git a/reference/bc/functions/bcround.xml b/reference/bc/functions/bcround.xml index a5ffa6acaa3e..b3529c2a71a8 100644 --- a/reference/bc/functions/bcround.xml +++ b/reference/bc/functions/bcround.xml @@ -261,6 +261,7 @@ string(4) "-1.5" bcceil bcfloor + BcMath\Number::round From 67ad21fd0fdffb36582bb5b5d2462e52a596efbb Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Fri, 29 Nov 2024 11:02:36 +0900 Subject: [PATCH 17/42] Created compare() --- reference/bc/bcmath/number/compare.xml | 225 +++++++++++++++++++++++++ reference/bc/functions/bccomp.xml | 7 + 2 files changed, 232 insertions(+) create mode 100644 reference/bc/bcmath/number/compare.xml diff --git a/reference/bc/bcmath/number/compare.xml b/reference/bc/bcmath/number/compare.xml new file mode 100644 index 000000000000..a6ebededf7f1 --- /dev/null +++ b/reference/bc/bcmath/number/compare.xml @@ -0,0 +1,225 @@ + + + + BcMath\Number::compare + Compares two arbitrary precision numbers + + + + &reftitle.description; + + public intBcMath\Number::compare + BcMath\Numberstringintnum + intnullscale&null; + + + Compare two arbitrary precision numbers. + This method behaves similar to the spaceship operator. + + + + + &reftitle.parameters; + + + num + + + The value to be compared to. + + + + + + + + + + &reftitle.returnvalues; + + Returns 0 if the two numbers are equal, 1 if the + this object is larger than the num, -1 otherwise. + + + + + + + + &reftitle.examples; + + <methodname>BcMath\Number::compare</methodname> example when <parameter>scale</parameter> is not specified + +compare(new BcMath\Number('1.234')), + $number->compare('1.23400'), + $number->compare('1.23401'), + $number->compare(1), +); +?> +]]> + + &example.outputs; + + + + + + + <methodname>BcMath\Number::compare</methodname> example of explicitly specifying <parameter>scale</parameter> + +compare(new BcMath\Number('1.299'), 1), + $number->compare('1.24', 2), + $number->compare('1.22', 2), + $number->compare(1, 0), +); +?> +]]> + + &example.outputs; + + + + + + + + + + + BcMath\Number can perform comparison using operators. The comparison with + the operator behaves the same as when the method argument scale is &null;. + + + Example of comparison using operators + +="' . PHP_EOL; +var_dump( + $number >= new BcMath\Number('1.234'), + $number >= '1.23400', + $number >= '1.23401', + $number >= 1, +); + +echo PHP_EOL . 'case ">"' . PHP_EOL; +var_dump( + $number > new BcMath\Number('1.234'), + $number > '1.23400', + $number > '1.23401', + $number > 1, +); + +echo PHP_EOL . 'case "<="' . PHP_EOL; +var_dump( + $number <= new BcMath\Number('1.234'), + $number <= '1.23400', + $number <= '1.23401', + $number <= 1, +); + +echo PHP_EOL . 'case "<"' . PHP_EOL; +var_dump( + $number < new BcMath\Number('1.234'), + $number < '1.23400', + $number < '1.23401', + $number < 1, +); +?> +]]> + + &example.outputs; + +=" +bool(true) +bool(true) +bool(false) +bool(true) + +case ">" +bool(false) +bool(false) +bool(false) +bool(true) + +case "<=" +bool(true) +bool(true) +bool(true) +bool(false) + +case "<" +bool(false) +bool(false) +bool(true) +bool(false) +]]> + + + + + + &reftitle.seealso; + + bccomp + + + + + diff --git a/reference/bc/functions/bccomp.xml b/reference/bc/functions/bccomp.xml index 052c5d4f6718..bc91a27be654 100644 --- a/reference/bc/functions/bccomp.xml +++ b/reference/bc/functions/bccomp.xml @@ -103,6 +103,13 @@ echo bccomp('1.00001', '1', 5); // 1 + + + &reftitle.seealso; + + BcMath\Number::compare + + + + + When the BcMath\Number::scale of the result object is automatically set, + the BcMath\Number::scale of this object is used. However, in cases such + as indivisible division, the BcMath\Number::scale of the result is expanded. + Expansion is done only as needed, up to a maximum of +10. + + + That is, if the BcMath\Number::scale of this object is 5, + the BcMath\Number::scale of the result is between 5 and + 15. + + + This behavior is the same as BcMath\Number::div, so please see that for details. + + + + + &reftitle.examples; + + <methodname>BcMath\Number::sqrt</methodname> example + +sqrt(), + new BcMath\Number('2')->sqrt(3), + new BcMath\Number('4')->sqrt(), + new BcMath\Number('4')->sqrt(3), +); +?> +]]> + + &example.outputs; + + + string(12) "1.4142135623" + ["scale"]=> + int(10) +} +object(BcMath\Number)#3 (2) { + ["value"]=> + string(5) "1.414" + ["scale"]=> + int(3) +} +object(BcMath\Number)#4 (2) { + ["value"]=> + string(1) "2" + ["scale"]=> + int(0) +} +object(BcMath\Number)#5 (2) { + ["value"]=> + string(5) "2.000" + ["scale"]=> + int(3) +} +]]> + + + + + + &reftitle.seealso; + + bcsqrt + BcMath\Number::div + BcMath\Number::pow + + + + + diff --git a/reference/bc/functions/bcsqrt.xml b/reference/bc/functions/bcsqrt.xml index 4da28a897f1d..077c653e3105 100644 --- a/reference/bc/functions/bcsqrt.xml +++ b/reference/bc/functions/bcsqrt.xml @@ -113,6 +113,7 @@ echo bcsqrt('2', 3); // 1.414 bcpow + BcMath\Number::sqrt From 7b51ff89a5a84e6b4ff0b1797c3bd6095867e031 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:08:17 +0900 Subject: [PATCH 19/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index 76a51fdf1ac2..5200237e0aa8 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -8,11 +8,12 @@
&reftitle.intro; - - A class for an arbitrary precision number. These objects support overloaded + + A class for an arbitrary precision number. + These objects support overloaded arithmetic and comparison operators. - + This class is not affected by bcmath.scale in &php.ini;. From 19d38dde784fb39b62777d00d8e37946a0eb627e Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:08:29 +0900 Subject: [PATCH 20/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index 5200237e0aa8..f64af2ef48cf 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -16,7 +16,9 @@ - This class is not affected by bcmath.scale in &php.ini;. + + This class is not affected by bcmath.scale in &php.ini;. + From 88ca28eb11288ecd1b21faa8aeda51e2b1c5d17b Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:08:37 +0900 Subject: [PATCH 21/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index f64af2ef48cf..4722dd5de309 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -80,9 +80,9 @@ scale - + The scale value currently set on the object. - + From 1917ae39abd649618715df84cde3008c7f2bd162 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:08:46 +0900 Subject: [PATCH 22/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index 4722dd5de309..d0f371ef0727 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -72,9 +72,9 @@ value - + A string representation of an arbitrary precision number. - + From 646fe0152bd96d02335de3fe1fe0ebcdc24f6806 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:09:01 +0900 Subject: [PATCH 23/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index d0f371ef0727..9230eaa62f3f 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -23,8 +23,7 @@ - For more information about calculations with operators, see the documentation - for the methods that correspond to the operators. + The behavior of an overloaded operator is that of the corresponding method.
From 228cba8d2e89145cc448a5a4a6f3e16ba1841f64 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:09:17 +0900 Subject: [PATCH 24/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath/number/compare.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath/number/compare.xml b/reference/bc/bcmath/number/compare.xml index a6ebededf7f1..5958d450d78a 100644 --- a/reference/bc/bcmath/number/compare.xml +++ b/reference/bc/bcmath/number/compare.xml @@ -37,8 +37,9 @@ &reftitle.returnvalues; - Returns 0 if the two numbers are equal, 1 if the - this object is larger than the num, -1 otherwise. + Returns 0 if the two numbers are equal, + 1 if $this is greater than num, + -1 otherwise. From 3ffc20725607cc207a4b5ede0f0b465c076a32b7 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:09:38 +0900 Subject: [PATCH 25/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath/number/construct.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/reference/bc/bcmath/number/construct.xml b/reference/bc/bcmath/number/construct.xml index c91d68290277..cbf2744a3377 100644 --- a/reference/bc/bcmath/number/construct.xml +++ b/reference/bc/bcmath/number/construct.xml @@ -23,10 +23,11 @@ num - An int or string value. If num is a - int, The BcMath\Number::scale is always set to 0. - If num is a string, it must be a valid number. - The BcMath\Number::scale is automatically set by parsing the string. + An int or string value. + If num is a int, + the BcMath\Number::scale is always set to 0. + If num is a string, it must be a valid number, + and the BcMath\Number::scale is automatically set by parsing the string. From 22792d51060c32ab27b865258b61264d18c09956 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 2 Dec 2024 13:07:27 +0900 Subject: [PATCH 26/42] Address comments and more --- reference/bc/bcmath.number.xml | 8 +- reference/bc/bcmath/number/add.xml | 126 ++--------------- reference/bc/bcmath/number/ceil.xml | 5 +- reference/bc/bcmath/number/compare.xml | 93 ------------- reference/bc/bcmath/number/div.xml | 143 +++----------------- reference/bc/bcmath/number/divmod.xml | 32 ++--- reference/bc/bcmath/number/floor.xml | 5 +- reference/bc/bcmath/number/mod.xml | 120 ++--------------- reference/bc/bcmath/number/mul.xml | 112 +-------------- reference/bc/bcmath/number/pow.xml | 165 +++-------------------- reference/bc/bcmath/number/powmod.xml | 22 ++- reference/bc/bcmath/number/round.xml | 2 +- reference/bc/bcmath/number/serialize.xml | 5 +- reference/bc/bcmath/number/sqrt.xml | 34 ++--- reference/bc/bcmath/number/sub.xml | 114 +--------------- reference/bc/bcmath/number/tostring.xml | 3 +- 16 files changed, 116 insertions(+), 873 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index 9230eaa62f3f..50f7e5342cf9 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -17,13 +17,15 @@ - This class is not affected by bcmath.scale in &php.ini;. + This class is not affected by bcmath.scale + in &php.ini;. - The behavior of an overloaded operator is that of the corresponding method. + The behavior of an overloaded operator is the same as specifying &null; for the + scale parameter in the corresponding method. @@ -81,6 +83,8 @@ The scale value currently set on the object. + For objects resulting from calculations, this value is set automatically unless explicitly + specify the scale parameter in the calculation method. diff --git a/reference/bc/bcmath/number/add.xml b/reference/bc/bcmath/number/add.xml index 7858118d247f..40aa4d0361a8 100644 --- a/reference/bc/bcmath/number/add.xml +++ b/reference/bc/bcmath/number/add.xml @@ -13,7 +13,7 @@ intnullscale&null; - Adds this object and num. + Adds $this and num. @@ -38,7 +38,13 @@ Returns the result of addition as a new BcMath\Number object. - The same is true for calculations using operators that correspond to this method. + When the BcMath\Number::scale of the result object is automatically set, + the larger BcMath\Number::scale of the two numbers used for addition is used. + + + That is, if the BcMath\Number::scales of two values are 2 + and 5 respectively, the BcMath\Number::scale of the result + will be 5. @@ -51,28 +57,6 @@ scale is outside the valid range - - When using the operator, throw a ValueError if one of the operands - is string and not a well-formed BCMath numeric string. - - - - - Auto scale - - When the BcMath\Number::scale of the result object is automatically set, - the larger BcMath\Number::scale of the two numbers used for addition is used. - - - That is, if the BcMath\Number::scales of two values are 2 - and 5 respectively, the BcMath\Number::scale of the result - will be 5. - - - If either of the two values is a string, the BcMath\Number::scale - of the string value is automatically obtained. For int, scale - is treated as 0. - @@ -170,100 +154,6 @@ object(BcMath\Number)#4 (2) { - - Operator Overload - - BcMath\Number can perform addition using operators. The calculation with - the operator behaves the same as when the method argument scale is &null;. - - - Example of addition using operators - - -]]> - - &example.outputs; - - - string(5) "1.234" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(7) "3.57967" - ["scale"]=> - int(5) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(8) "-2.22278" - ["scale"]=> - int(5) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(5) "8.234" - ["scale"]=> - int(3) -} -]]> - - - - - Examples of increment and shorthand addition using operators - - -]]> - - &example.outputs; - - - string(5) "1.234" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(5) "3.579" - ["scale"]=> - int(3) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(5) "2.234" - ["scale"]=> - int(3) -} -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/ceil.xml b/reference/bc/bcmath/number/ceil.xml index dcb930b3976c..8225b87d7c92 100644 --- a/reference/bc/bcmath/number/ceil.xml +++ b/reference/bc/bcmath/number/ceil.xml @@ -13,13 +13,14 @@ Returns the next highest integer value by rounding up - this object if necessary. + $this if necessary. &reftitle.parameters; - &no.function.parameters; + &no.function.parameters; + &reftitle.returnvalues; diff --git a/reference/bc/bcmath/number/compare.xml b/reference/bc/bcmath/number/compare.xml index 5958d450d78a..94ffa6de8123 100644 --- a/reference/bc/bcmath/number/compare.xml +++ b/reference/bc/bcmath/number/compare.xml @@ -103,99 +103,6 @@ int(0) - - - - - BcMath\Number can perform comparison using operators. The comparison with - the operator behaves the same as when the method argument scale is &null;. - - - Example of comparison using operators - -="' . PHP_EOL; -var_dump( - $number >= new BcMath\Number('1.234'), - $number >= '1.23400', - $number >= '1.23401', - $number >= 1, -); - -echo PHP_EOL . 'case ">"' . PHP_EOL; -var_dump( - $number > new BcMath\Number('1.234'), - $number > '1.23400', - $number > '1.23401', - $number > 1, -); - -echo PHP_EOL . 'case "<="' . PHP_EOL; -var_dump( - $number <= new BcMath\Number('1.234'), - $number <= '1.23400', - $number <= '1.23401', - $number <= 1, -); - -echo PHP_EOL . 'case "<"' . PHP_EOL; -var_dump( - $number < new BcMath\Number('1.234'), - $number < '1.23400', - $number < '1.23401', - $number < 1, -); -?> -]]> - - &example.outputs; - -=" -bool(true) -bool(true) -bool(false) -bool(true) - -case ">" -bool(false) -bool(false) -bool(false) -bool(true) - -case "<=" -bool(true) -bool(true) -bool(true) -bool(false) - -case "<" -bool(false) -bool(false) -bool(true) -bool(false) -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index b264910f1ed0..a1a16118582b 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -1,5 +1,5 @@ - + BcMath\Number::div Divides by an arbitrary precision number @@ -13,7 +13,7 @@ intnullscale&null; - Divides this object by num. + Divides $this by num. @@ -37,40 +37,6 @@ Returns the result of division as a new BcMath\Number object. - - - - - - &reftitle.errors; - - This method throws a ValueError in the following cases: - - num is string and not a well-formed BCMath numeric string - scale is outside the valid range - BcMath\Number::scale of the result object is outside the valid range - - - - This method throws a DivisionByZeroError exception if - num is 0. - - - When using the operator, throw a ValueError in the following cases: - - One of the operands is string and not a well-formed BCMath numeric string - BcMath\Number::scale of the result object is outside the valid range - - - - When using the operator, throw a DivisionByZeroError exception if - divisor is 0. - - - - - - When the BcMath\Number::scale of the result object is automatically set, the BcMath\Number::scale of the dividend is used. However, in cases such @@ -127,8 +93,22 @@ object(BcMath\Number)#4 (2) { ]]> - - + + + + &reftitle.errors; + + This method throws a ValueError in the following cases: + + num is string and not a well-formed BCMath numeric string + scale is outside the valid range + BcMath\Number::scale of the result object is outside the valid range + + + + This method throws a DivisionByZeroError exception if + num is 0. + @@ -226,93 +206,6 @@ object(BcMath\Number)#4 (2) { - - - - - BcMath\Number can perform division using operators. The calculation with - the operator behaves the same as when the method argument scale is &null;. - - - Example of division using operators - - -]]> - - &example.outputs; - - - string(5) "0.002" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(5) "0.001" - ["scale"]=> - int(3) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(16) "-0.0006666666666" - ["scale"]=> - int(13) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(9) "0.0000625" - ["scale"]=> - int(7) -} -]]> - - - - - Examples of shorthand division using operators - - -]]> - - &example.outputs; - - - string(1) "3" - ["scale"]=> - int(0) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(3) "1.5" - ["scale"]=> - int(1) -} -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/divmod.xml b/reference/bc/bcmath/number/divmod.xml index a4d569cecf83..964cf6a33165 100644 --- a/reference/bc/bcmath/number/divmod.xml +++ b/reference/bc/bcmath/number/divmod.xml @@ -13,7 +13,7 @@ intnullscale&null; - Gets the quotient and remainder of dividing this object by num. + Gets the quotient and remainder of dividing $this by num. @@ -27,26 +27,6 @@ BcMath\Number object and the second element is the remainder as a new BcMath\Number object. - - The quotient is always an integer value, so BcMath\Number::scale is always 0. - - - - - &reftitle.errors; - - - - - - - - - - - - - The quotient is always an integer value, so BcMath\Number::scale of the quotient will always be 0, regardless of whether explicitly specify scale. @@ -62,8 +42,14 @@ and 5 respectively, the BcMath\Number::scale of the remainder will be 5. - - + + + + &reftitle.errors; + + + + diff --git a/reference/bc/bcmath/number/floor.xml b/reference/bc/bcmath/number/floor.xml index 4f089cb9f3fe..73019805c6c8 100644 --- a/reference/bc/bcmath/number/floor.xml +++ b/reference/bc/bcmath/number/floor.xml @@ -13,13 +13,14 @@ Returns the next highest integer value by rounding down - this object if necessary. + $this if necessary. &reftitle.parameters; - &no.function.parameters; + &no.function.parameters; + diff --git a/reference/bc/bcmath/number/mod.xml b/reference/bc/bcmath/number/mod.xml index 64c85a9de583..28a33a36fefd 100644 --- a/reference/bc/bcmath/number/mod.xml +++ b/reference/bc/bcmath/number/mod.xml @@ -13,9 +13,9 @@ intnullscale&null; - Gets the remainder of dividing this object by num. + Gets the remainder of dividing $this by num. Unless num is 0, the result has the same sign - as this object. + as $this. @@ -27,33 +27,20 @@ Returns the modulus as a new BcMath\Number object. - - + + When the BcMath\Number::scale of the result object is automatically set, + the larger BcMath\Number::scale of the two numbers used for modulus operation is used. + + + &reftitle.errors; - + - + - - - - - - - - - - - When the BcMath\Number::scale of the result object is automatically set, - the larger BcMath\Number::scale of the two numbers used for modulus operation is used. - - - - - @@ -151,93 +138,6 @@ object(BcMath\Number)#4 (2) { - - - - - BcMath\Number can perform modulus operation using operators. The calculation with - the operator behaves the same as when the method argument scale is &null;. - - - Example of modulus operation using operators - - -]]> - - &example.outputs; - - - string(4) "-7.1" - ["scale"]=> - int(1) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(5) "-0.66" - ["scale"]=> - int(2) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(3) "0.0" - ["scale"]=> - int(1) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(4) "-1.1" - ["scale"]=> - int(1) -} -]]> - - - - - Examples of shorthand modulus operation using operators - - -]]> - - &example.outputs; - - - string(1) "3" - ["scale"]=> - int(0) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(1) "1" - ["scale"]=> - int(0) -} -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/mul.xml b/reference/bc/bcmath/number/mul.xml index 8cd3a3d1cb9d..098596547a22 100644 --- a/reference/bc/bcmath/number/mul.xml +++ b/reference/bc/bcmath/number/mul.xml @@ -13,7 +13,7 @@ intnullscale&null; - Multiplies this object by num. + Multiplies $this by num. @@ -37,21 +37,6 @@ Returns the result of multiplication as a new BcMath\Number object. - - - - - - &reftitle.errors; - - - - - - - - - When the BcMath\Number::scale of the result object is automatically set, the sum of the BcMath\Number::scales of the two values used for multiplication is used. @@ -61,8 +46,12 @@ and 5 respectively, the BcMath\Number::scale of the result will be 7. - - + + + + &reftitle.errors; + + @@ -160,93 +149,6 @@ object(BcMath\Number)#4 (2) { - - - - - BcMath\Number can perform multiplication using operators. The calculation with - the operator behaves the same as when the method argument scale is &null;. - - - Example of multiplication using operators - - -]]> - - &example.outputs; - - - string(5) "1.234" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(9) "2.8944704" - ["scale"]=> - int(7) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(7) "-4.1956" - ["scale"]=> - int(4) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(5) "8.638" - ["scale"]=> - int(3) -} -]]> - - - - - Examples of shorthand multiplication using operators - - -]]> - - &example.outputs; - - - string(5) "1.234" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(8) "2.893730" - ["scale"]=> - int(6) -} -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/pow.xml b/reference/bc/bcmath/number/pow.xml index 755ae9692c33..e9c133e94912 100644 --- a/reference/bc/bcmath/number/pow.xml +++ b/reference/bc/bcmath/number/pow.xml @@ -13,7 +13,7 @@ intnullscale&null; - Raises this object to the exponent power. + Raises $this to the exponent power. @@ -25,8 +25,8 @@ The exponent. Must be a value with no fractional part. - The valid range of the exponent is platform specific, but is at least - -2147483648 to 2147483647. + The valid range of the exponent is platform specific, + but is at least -2147483648 to 2147483647. @@ -39,43 +39,6 @@ Returns the result of power as a new BcMath\Number object. - - - - - - &reftitle.errors; - - This method throws a ValueError in the following cases: - - exponent is string and not a well-formed BCMath numeric string - exponent has a fractional part - exponent or scale is outside the valid range - BcMath\Number::scale of the result object is outside the valid range - - - - This method throws a DivisionByZeroError exception if this object's value - is 0 and exponent is a negative value. - - - When using the operator, throws a ValueError in the following cases: - - exponent is string and not a well-formed BCMath numeric string - exponent has a fractional part - exponent is outside the valid range - BcMath\Number::scale of the result object is outside the valid range - - - - When using the operator, throw a DivisionByZeroError exception If the left - operand is 0 and the right operand is a negative value. - - - - - - When the BcMath\Number::scale of the result object is automatically set, depending on the value of exponent, the BcMath\Number::scale @@ -112,8 +75,23 @@ a maximum of +10. This behavior is the same as BcMath\Number::div, so please see that for details. - - + + + + &reftitle.errors; + + This method throws a ValueError in the following cases: + + exponent is string and not a well-formed BCMath numeric string + exponent has a fractional part + exponent or scale is outside the valid range + BcMath\Number::scale of the result object is outside the valid range + + + + This method throws a DivisionByZeroError exception if $this's value + is 0 and exponent is a negative value. + @@ -211,109 +189,6 @@ object(BcMath\Number)#4 (2) { - - - - - BcMath\Number can perform power using operators. The calculation with - the operator behaves the same as when the method argument scale is &null;. - - - Example of power using operators - - -]]> - - &example.outputs; - - - string(3) "3.0" - ["scale"]=> - int(1) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(9) "243.00000" - ["scale"]=> - int(5) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(13) "0.33333333333" - ["scale"]=> - int(11) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(1) "1" - ["scale"]=> - int(0) -} -]]> - - - - - Examples of shorthand power using operators - - -]]> - - &example.outputs; - - - string(3) "1.2" - ["scale"]=> - int(1) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(4) "1.44" - ["scale"]=> - int(2) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(13) "0.83333333333" - ["scale"]=> - int(11) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(1) "1" - ["scale"]=> - int(0) -} -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/powmod.xml b/reference/bc/bcmath/number/powmod.xml index 2c2e9441ebb2..476cfee85273 100644 --- a/reference/bc/bcmath/number/powmod.xml +++ b/reference/bc/bcmath/number/powmod.xml @@ -1,5 +1,5 @@ - + BcMath\Number::powmod Raises an arbitrary precision number, reduced by a specified modulus @@ -14,9 +14,8 @@ intnullscale&null; - Use the fast-exponentiation method to raise this object to the power - exponent with respect to the modulus - modulus. + Use the fast-exponentiation method to raise $this to the power + exponent with respect to the modulus modulus. @@ -48,6 +47,10 @@ Returns the result as a new BcMath\Number object. + + When the BcMath\Number::scale of the result object is automatically set, + the BcMath\Number::scale of the result object will always be 0. + @@ -57,7 +60,7 @@ exponent or modulus is string and not a well-formed BCMath numeric string - This object, exponent or modulus has a fractional part + $this, exponent or modulus has a fractional part exponent is a negative value scale is outside the valid range @@ -68,15 +71,6 @@ - - - - - When the BcMath\Number::scale of the result object is automatically set, - the BcMath\Number::scale of the result object will always be 0. - - - &reftitle.examples; diff --git a/reference/bc/bcmath/number/round.xml b/reference/bc/bcmath/number/round.xml index 6956551596e1..4d1dbfc34125 100644 --- a/reference/bc/bcmath/number/round.xml +++ b/reference/bc/bcmath/number/round.xml @@ -13,7 +13,7 @@ RoundingModemodeRoundingMode::HalfAwayFromZero - Returns the rounded value of this object to + Returns the rounded value of $this to specified precision (number of digits after the decimal point). precision can also be negative or zero (default). diff --git a/reference/bc/bcmath/number/serialize.xml b/reference/bc/bcmath/number/serialize.xml index b6ce00bc1709..144aa329ed48 100644 --- a/reference/bc/bcmath/number/serialize.xml +++ b/reference/bc/bcmath/number/serialize.xml @@ -12,13 +12,14 @@ - Serializes this object. + Serializes $this. &reftitle.parameters; - &no.function.parameters; + &no.function.parameters; + &reftitle.seealso; diff --git a/reference/bc/bcmath/number/sqrt.xml b/reference/bc/bcmath/number/sqrt.xml index 84b565dfa7e2..11c6f892a4f6 100644 --- a/reference/bc/bcmath/number/sqrt.xml +++ b/reference/bc/bcmath/number/sqrt.xml @@ -1,5 +1,5 @@ - + BcMath\Number::sqrt Gets the square root of an arbitrary precision number @@ -12,7 +12,7 @@ intnullscale&null; - Return the square root of this object. + Return the square root of $this. @@ -28,6 +28,17 @@ Returns the square root as a new BcMath\Number object. + + When the BcMath\Number::scale of the result object is automatically set, + the BcMath\Number::scale of this object is used. However, in cases such + as indivisible division, the BcMath\Number::scale of the result is expanded. + Expansion is done only as needed, up to a maximum of +10. + + + That is, if the BcMath\Number::scale of this object is 5, + the BcMath\Number::scale of the result is between 5 and + 15. + @@ -42,25 +53,6 @@ - - - - - When the BcMath\Number::scale of the result object is automatically set, - the BcMath\Number::scale of this object is used. However, in cases such - as indivisible division, the BcMath\Number::scale of the result is expanded. - Expansion is done only as needed, up to a maximum of +10. - - - That is, if the BcMath\Number::scale of this object is 5, - the BcMath\Number::scale of the result is between 5 and - 15. - - - This behavior is the same as BcMath\Number::div, so please see that for details. - - - &reftitle.examples; diff --git a/reference/bc/bcmath/number/sub.xml b/reference/bc/bcmath/number/sub.xml index 34b5470482de..30039260083b 100644 --- a/reference/bc/bcmath/number/sub.xml +++ b/reference/bc/bcmath/number/sub.xml @@ -13,7 +13,7 @@ intnullscale&null; - Subtracts num from this object. + Subtracts num from $this. @@ -37,26 +37,17 @@ Returns the result of subtraction as a new BcMath\Number object. - - - - - - - - - - When the BcMath\Number::scale of the result object is automatically set, the larger BcMath\Number::scale of the two numbers used for subtraction is used. - - - + + + + &reftitle.examples; @@ -152,101 +143,6 @@ object(BcMath\Number)#4 (2) { - - - - - BcMath\Number can perform subtraction using operators. The calculation with - the operator behaves the same as when the method argument scale is &null;. - - - Example of subtraction using operators - - -]]> - - &example.outputs; - - - string(5) "1.234" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(8) "-1.11167" - ["scale"]=> - int(5) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(7) "4.69078" - ["scale"]=> - int(5) -} -object(BcMath\Number)#4 (2) { - ["value"]=> - string(6) "-5.766" - ["scale"]=> - int(3) -} -]]> - - - - - Examples of decrement and shorthand subtraction using operators - - -]]> - - &example.outputs; - - - string(5) "1.234" - ["scale"]=> - int(3) -} -object(BcMath\Number)#3 (2) { - ["value"]=> - string(6) "-1.111" - ["scale"]=> - int(3) -} -object(BcMath\Number)#2 (2) { - ["value"]=> - string(5) "0.234" - ["scale"]=> - int(3) -} -]]> - - - - &reftitle.seealso; diff --git a/reference/bc/bcmath/number/tostring.xml b/reference/bc/bcmath/number/tostring.xml index 091d4a5f817b..6059b5b8400a 100644 --- a/reference/bc/bcmath/number/tostring.xml +++ b/reference/bc/bcmath/number/tostring.xml @@ -18,7 +18,8 @@ &reftitle.parameters; - &no.function.parameters; + &no.function.parameters; + &reftitle.returnvalues; From 10e1602841b5accb831629ac06a778177a50b300 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 2 Dec 2024 13:13:50 +0900 Subject: [PATCH 27/42] changed "larger" to "greater" and "smaller than" to "less than" --- reference/bc/bcmath/number/add.xml | 2 +- reference/bc/bcmath/number/div.xml | 2 +- reference/bc/bcmath/number/divmod.xml | 2 +- reference/bc/bcmath/number/mod.xml | 2 +- reference/bc/bcmath/number/sub.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/reference/bc/bcmath/number/add.xml b/reference/bc/bcmath/number/add.xml index 40aa4d0361a8..7024f334be6f 100644 --- a/reference/bc/bcmath/number/add.xml +++ b/reference/bc/bcmath/number/add.xml @@ -39,7 +39,7 @@ When the BcMath\Number::scale of the result object is automatically set, - the larger BcMath\Number::scale of the two numbers used for addition is used. + the greater BcMath\Number::scale of the two numbers used for addition is used. That is, if the BcMath\Number::scales of two values are 2 diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index a1a16118582b..63579dc21d94 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -53,7 +53,7 @@ +10. A 0 at the end of the result is considered not to need expansion, so the BcMath\Number::scale is reduced by that amount. - The BcMath\Number::scale will never be smaller than the BcMath\Number::scale + The BcMath\Number::scale will never be less than the BcMath\Number::scale before expansion. diff --git a/reference/bc/bcmath/number/divmod.xml b/reference/bc/bcmath/number/divmod.xml index 964cf6a33165..6a9764a7c32f 100644 --- a/reference/bc/bcmath/number/divmod.xml +++ b/reference/bc/bcmath/number/divmod.xml @@ -35,7 +35,7 @@ If scale is explicitly specified, BcMath\Number::scale of the remainder will be the specified value. When the BcMath\Number::scale of the result's remainder object is automatically set, - the larger BcMath\Number::scale of the two numbers used for modulus operation is used. + the greater BcMath\Number::scale of the two numbers used for modulus operation is used. That is, if the BcMath\Number::scales of two values are 2 diff --git a/reference/bc/bcmath/number/mod.xml b/reference/bc/bcmath/number/mod.xml index 28a33a36fefd..d092af26f27c 100644 --- a/reference/bc/bcmath/number/mod.xml +++ b/reference/bc/bcmath/number/mod.xml @@ -29,7 +29,7 @@ When the BcMath\Number::scale of the result object is automatically set, - the larger BcMath\Number::scale of the two numbers used for modulus operation is used. + the greater BcMath\Number::scale of the two numbers used for modulus operation is used. diff --git a/reference/bc/bcmath/number/sub.xml b/reference/bc/bcmath/number/sub.xml index 30039260083b..51835a7a17e7 100644 --- a/reference/bc/bcmath/number/sub.xml +++ b/reference/bc/bcmath/number/sub.xml @@ -39,7 +39,7 @@ When the BcMath\Number::scale of the result object is automatically set, - the larger BcMath\Number::scale of the two numbers used for subtraction is used. + the greater BcMath\Number::scale of the two numbers used for subtraction is used. From cafb7ff583d5bccf04ecd0affa332601f96d9fd6 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 2 Dec 2024 13:15:04 +0900 Subject: [PATCH 28/42] typo --- reference/bc/bcmath/number/div.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index 63579dc21d94..f969ee83d06a 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -57,7 +57,7 @@ before expansion. - Example of <property>BcMath\Number::scale</property> od result object + Example of <property>BcMath\Number::scale</property> of result object Date: Mon, 2 Dec 2024 13:47:25 +0900 Subject: [PATCH 29/42] Changed the scale param desctiption --- reference/bc/bcmath/number/compare.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath/number/compare.xml b/reference/bc/bcmath/number/compare.xml index 94ffa6de8123..f0ba6e0cb40c 100644 --- a/reference/bc/bcmath/number/compare.xml +++ b/reference/bc/bcmath/number/compare.xml @@ -29,8 +29,15 @@ - - + + scale + + + Specify the scale to use for comparison. + If &null;, all digits are used in the comparison. + + + From cd6f8d73cbb0d40bb3de4c58fcad7b9b2d4d6b24 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 2 Dec 2024 13:55:22 +0900 Subject: [PATCH 30/42] Deleted unnecessary descriptions --- reference/bc/bcmath/number/pow.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/bcmath/number/pow.xml b/reference/bc/bcmath/number/pow.xml index e9c133e94912..f0d99d463257 100644 --- a/reference/bc/bcmath/number/pow.xml +++ b/reference/bc/bcmath/number/pow.xml @@ -1,5 +1,5 @@ - + BcMath\Number::pow Raises an arbitrary precision number From 68995866a5bd158f3bd4398e4fd9ce7f67e0c2d9 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 2 Dec 2024 13:57:15 +0900 Subject: [PATCH 31/42] Avoid nesting includes --- reference/bc/bcmath/number/round.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath/number/round.xml b/reference/bc/bcmath/number/round.xml index 4d1dbfc34125..d1669e97d2d4 100644 --- a/reference/bc/bcmath/number/round.xml +++ b/reference/bc/bcmath/number/round.xml @@ -25,8 +25,14 @@ - - + + mode + + + Specifies the rounding mode. + + + From c860c08fa86431111e42dcb4fc8ed540571cf114 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:21:17 +0900 Subject: [PATCH 32/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index 50f7e5342cf9..aba34ff5b678 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -17,8 +17,9 @@ - This class is not affected by bcmath.scale - in &php.ini;. + This class is not affected by the + bcmath.scale + INI directive set in &php.ini;. From 043e7e2f6ec6ec0dc93a0c5f85891c7daf764006 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:21:27 +0900 Subject: [PATCH 33/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index aba34ff5b678..00dda9ef89ce 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -26,7 +26,7 @@ The behavior of an overloaded operator is the same as specifying &null; for the - scale parameter in the corresponding method. + scale parameter on the corresponding method. From 5b1228f7169527c6ebbed5604033f1fab3bb36ea Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:22:01 +0900 Subject: [PATCH 34/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath.number.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath.number.xml b/reference/bc/bcmath.number.xml index 00dda9ef89ce..205df12422ca 100644 --- a/reference/bc/bcmath.number.xml +++ b/reference/bc/bcmath.number.xml @@ -84,8 +84,8 @@ The scale value currently set on the object. - For objects resulting from calculations, this value is set automatically unless explicitly - specify the scale parameter in the calculation method. + For objects resulting from calculations, this value is automatically computed and set, + unless the scale parameter was set in the calculation method. From d2e7031a7dc496dd7508fbab88d09f6bde276eb9 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:23:24 +0900 Subject: [PATCH 35/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath/number/div.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index f969ee83d06a..15a18b9e51c4 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -41,7 +41,7 @@ When the BcMath\Number::scale of the result object is automatically set, the BcMath\Number::scale of the dividend is used. However, in cases such as indivisible division, the BcMath\Number::scale of the result is expanded. - Expansion is done only as needed, up to a maximum of +10. + Expansion is done only as needed, up to a maximum of +10. That is, if the BcMath\Number::scale of the dividend is 5, From d4802319f31a2025e819342e9b5a17aa42047e43 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:23:43 +0900 Subject: [PATCH 36/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath/number/div.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index 15a18b9e51c4..577790a36a7f 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -51,8 +51,8 @@ Even in indivisible calculations, the BcMath\Number::scale will not always be +10. - A 0 at the end of the result is considered not to need expansion, so the - BcMath\Number::scale is reduced by that amount. + A 0 at the end of the result is considered not to need expansion, so the + BcMath\Number::scale is reduced by that amount. The BcMath\Number::scale will never be less than the BcMath\Number::scale before expansion. From cb0d697954883d5531be1fdc59008aaa6c136814 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:24:03 +0900 Subject: [PATCH 37/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath/number/div.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index 577790a36a7f..a9f5d1609348 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -53,8 +53,8 @@ +10. A 0 at the end of the result is considered not to need expansion, so the BcMath\Number::scale is reduced by that amount. - The BcMath\Number::scale will never be less than the BcMath\Number::scale - before expansion. + The BcMath\Number::scale will never be less than the + BcMath\Number::scale before expansion. Example of <property>BcMath\Number::scale</property> of result object From 6a353756746272310bf0b9e2e49532306c99e79f Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:24:14 +0900 Subject: [PATCH 38/42] address a comment Co-authored-by: Gina Peter Banyard --- reference/bc/bcmath/number/pow.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/bcmath/number/pow.xml b/reference/bc/bcmath/number/pow.xml index f0d99d463257..dca8ac0ba154 100644 --- a/reference/bc/bcmath/number/pow.xml +++ b/reference/bc/bcmath/number/pow.xml @@ -26,7 +26,7 @@ The exponent. Must be a value with no fractional part. The valid range of the exponent is platform specific, - but is at least -2147483648 to 2147483647. + but it is at least -2147483648 to 2147483647. From 60a76f1a190876f5457ef85b89dfd5bea1cc8e72 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Tue, 17 Dec 2024 00:35:53 +0900 Subject: [PATCH 39/42] Moved varlistentry of scale parameter to add() --- language-snippets.ent | 5 ----- reference/bc/bcmath/number/add.xml | 10 +++++++++- reference/bc/bcmath/number/div.xml | 4 ++-- reference/bc/bcmath/number/mul.xml | 2 +- reference/bc/bcmath/number/pow.xml | 4 ++-- reference/bc/bcmath/number/powmod.xml | 4 ++-- reference/bc/bcmath/number/sqrt.xml | 4 ++-- reference/bc/bcmath/number/sub.xml | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/language-snippets.ent b/language-snippets.ent index db3f00090fa7..fcf2afe88160 100644 --- a/language-snippets.ent +++ b/language-snippets.ent @@ -2155,11 +2155,6 @@ of digits after the decimal place in the result. If omitted, it will default to globally with the bcscale function, or fallback to 0 if this has not been set.'> - -scalescale explicitly -specified for calculation results. If &null;, the scale of the calculation -result will be set automatically.'> - If an int between -128 and 255 inclusive is provided, it is interpreted as diff --git a/reference/bc/bcmath/number/add.xml b/reference/bc/bcmath/number/add.xml index 7024f334be6f..7bdfaff6aae1 100644 --- a/reference/bc/bcmath/number/add.xml +++ b/reference/bc/bcmath/number/add.xml @@ -28,7 +28,15 @@ - &bc.number.scale.description; + + scale + + + scale explicitly specified for calculation results. + If &null;, the scale of the calculation result will be set automatically. + + + diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index a9f5d1609348..8efc19d425db 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -1,5 +1,5 @@ - + BcMath\Number::div Divides by an arbitrary precision number @@ -28,7 +28,7 @@ - &bc.number.scale.description; + diff --git a/reference/bc/bcmath/number/mul.xml b/reference/bc/bcmath/number/mul.xml index 098596547a22..aa3d55370fa6 100644 --- a/reference/bc/bcmath/number/mul.xml +++ b/reference/bc/bcmath/number/mul.xml @@ -28,7 +28,7 @@ - &bc.number.scale.description; + diff --git a/reference/bc/bcmath/number/pow.xml b/reference/bc/bcmath/number/pow.xml index dca8ac0ba154..f0644f633e82 100644 --- a/reference/bc/bcmath/number/pow.xml +++ b/reference/bc/bcmath/number/pow.xml @@ -1,5 +1,5 @@ - + BcMath\Number::pow Raises an arbitrary precision number @@ -30,7 +30,7 @@ - &bc.number.scale.description; + diff --git a/reference/bc/bcmath/number/powmod.xml b/reference/bc/bcmath/number/powmod.xml index 476cfee85273..fdc4cd1cf841 100644 --- a/reference/bc/bcmath/number/powmod.xml +++ b/reference/bc/bcmath/number/powmod.xml @@ -1,5 +1,5 @@ - + BcMath\Number::powmod Raises an arbitrary precision number, reduced by a specified modulus @@ -38,7 +38,7 @@ - &bc.number.scale.description; + diff --git a/reference/bc/bcmath/number/sqrt.xml b/reference/bc/bcmath/number/sqrt.xml index 11c6f892a4f6..b9df2e2f1caa 100644 --- a/reference/bc/bcmath/number/sqrt.xml +++ b/reference/bc/bcmath/number/sqrt.xml @@ -1,5 +1,5 @@ - + BcMath\Number::sqrt Gets the square root of an arbitrary precision number @@ -19,7 +19,7 @@ &reftitle.parameters; - &bc.number.scale.description; + diff --git a/reference/bc/bcmath/number/sub.xml b/reference/bc/bcmath/number/sub.xml index 51835a7a17e7..2d037b11ff60 100644 --- a/reference/bc/bcmath/number/sub.xml +++ b/reference/bc/bcmath/number/sub.xml @@ -28,7 +28,7 @@ - &bc.number.scale.description; + From 10b03c470f47d0d444bbba07a779a8060b4a439b Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Tue, 17 Dec 2024 00:40:55 +0900 Subject: [PATCH 40/42] Added a link to "spaceship operator" --- reference/bc/bcmath/number/compare.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/bcmath/number/compare.xml b/reference/bc/bcmath/number/compare.xml index f0ba6e0cb40c..22d2d40104f5 100644 --- a/reference/bc/bcmath/number/compare.xml +++ b/reference/bc/bcmath/number/compare.xml @@ -14,7 +14,7 @@ Compare two arbitrary precision numbers. - This method behaves similar to the spaceship operator. + This method behaves similar to the spaceship operator. From 6411e68fc0e4d058c87aa8982624e4272ae5d1ab Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Tue, 17 Dec 2024 00:42:39 +0900 Subject: [PATCH 41/42] fixed "+10" to "+10" --- reference/bc/bcmath/number/div.xml | 2 +- reference/bc/bcmath/number/pow.xml | 2 +- reference/bc/bcmath/number/sqrt.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index 8efc19d425db..8cd23522db15 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -50,7 +50,7 @@ Even in indivisible calculations, the BcMath\Number::scale will not always be - +10. + +10. A 0 at the end of the result is considered not to need expansion, so the BcMath\Number::scale is reduced by that amount. The BcMath\Number::scale will never be less than the diff --git a/reference/bc/bcmath/number/pow.xml b/reference/bc/bcmath/number/pow.xml index f0644f633e82..84eff1ff4fa9 100644 --- a/reference/bc/bcmath/number/pow.xml +++ b/reference/bc/bcmath/number/pow.xml @@ -72,7 +72,7 @@ If an indivisible division occurs due to a negative exponent, the BcMath\Number::scale of the result is expanded. Expansion is done only as needed, up to - a maximum of +10. + a maximum of +10. This behavior is the same as BcMath\Number::div, so please see that for details. diff --git a/reference/bc/bcmath/number/sqrt.xml b/reference/bc/bcmath/number/sqrt.xml index b9df2e2f1caa..be99915ff390 100644 --- a/reference/bc/bcmath/number/sqrt.xml +++ b/reference/bc/bcmath/number/sqrt.xml @@ -32,7 +32,7 @@ When the BcMath\Number::scale of the result object is automatically set, the BcMath\Number::scale of this object is used. However, in cases such as indivisible division, the BcMath\Number::scale of the result is expanded. - Expansion is done only as needed, up to a maximum of +10. + Expansion is done only as needed, up to a maximum of +10. That is, if the BcMath\Number::scale of this object is 5, From 57d7592159e523b08942ec0c1ff98a0c1a740799 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Tue, 17 Dec 2024 00:55:46 +0900 Subject: [PATCH 42/42] Moded a example code --- reference/bc/bcmath/number/div.xml | 76 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/reference/bc/bcmath/number/div.xml b/reference/bc/bcmath/number/div.xml index 8cd23522db15..26432822a848 100644 --- a/reference/bc/bcmath/number/div.xml +++ b/reference/bc/bcmath/number/div.xml @@ -55,44 +55,8 @@ BcMath\Number::scale is reduced by that amount. The BcMath\Number::scale will never be less than the BcMath\Number::scale before expansion. + See also the code example. - - Example of <property>BcMath\Number::scale</property> of result object - -div('10001'), - new BcMath\Number('0.001')->div('10001', 13), - new BcMath\Number('0.001')->div('100000000000001'), -); -?> -]]> - - &example.outputs; - - - 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) -} -]]> - - @@ -201,6 +165,44 @@ object(BcMath\Number)#4 (2) { ["scale"]=> int(2) } +]]> + + + + + <methodname>BcMath\Number::div</methodname> example of expansioning <property>BcMath\Number::scale</property> of result object + +div('10001'), + new BcMath\Number('0.001')->div('10001', 13), + new BcMath\Number('0.001')->div('100000000000001'), +); +?> +]]> + + &example.outputs; + + + 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) +} ]]>