From 00ac2703e51c2ca9cbdccf94ad449860ad96cd46 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Sat, 23 Nov 2024 16:02:18 +0900 Subject: [PATCH 01/12] Added bcceil, bcfloor, bcround and bcdivmod --- reference/bc/functions/bcceil.xml | 91 ++++++++ reference/bc/functions/bcdiv.xml | 1 + reference/bc/functions/bcdivmod.xml | 142 +++++++++++++ reference/bc/functions/bcfloor.xml | 91 ++++++++ reference/bc/functions/bcmod.xml | 1 + reference/bc/functions/bcround.xml | 316 ++++++++++++++++++++++++++++ reference/bc/versions.xml | 4 + 7 files changed, 646 insertions(+) create mode 100644 reference/bc/functions/bcceil.xml create mode 100644 reference/bc/functions/bcdivmod.xml create mode 100644 reference/bc/functions/bcfloor.xml create mode 100644 reference/bc/functions/bcround.xml diff --git a/reference/bc/functions/bcceil.xml b/reference/bc/functions/bcceil.xml new file mode 100644 index 000000000000..d95b07847740 --- /dev/null +++ b/reference/bc/functions/bcceil.xml @@ -0,0 +1,91 @@ + + + + + bcceil + Round arbitrary precision number fractions up + + + + &reftitle.description; + + stringbcceil + stringnum + + + Returns the next highest integer value by rounding up + num if necessary. + + + + + &reftitle.parameters; + + + + num + + + The value to round. + + + + + + + + + &reftitle.returnvalues; + + num rounded up to the next highest number as a string. + + + + + &reftitle.examples; + + + <function>ceil</function> example + + +]]> + + + + + + + &reftitle.seealso; + + + bcfloor + bcround + + + + + diff --git a/reference/bc/functions/bcdiv.xml b/reference/bc/functions/bcdiv.xml index 7c5fb94d4dbd..685dc5e437fe 100644 --- a/reference/bc/functions/bcdiv.xml +++ b/reference/bc/functions/bcdiv.xml @@ -95,6 +95,7 @@ echo bcdiv('105', '6.55957', 3); // 16.007 &reftitle.seealso; + bcmod bcmul diff --git a/reference/bc/functions/bcdivmod.xml b/reference/bc/functions/bcdivmod.xml new file mode 100644 index 000000000000..95831fd14ae1 --- /dev/null +++ b/reference/bc/functions/bcdivmod.xml @@ -0,0 +1,142 @@ + + + + + bcdivmod + Get the quotient and modulus of an arbitrary precision number + + + + &reftitle.description; + + stringbcdivmod + stringnum1 + stringnum2 + intnullscale&null; + + + Get the quotient and remainder of dividing num1 by + num2. + + + + + &reftitle.parameters; + + + + num1 + + + The dividend, as a string. + + + + + num2 + + + The divisor, as a string. + + + + &bc.scale.description; + + + + + + &reftitle.returnvalues; + + Returns an array, the first element is the quotient as a string and the second + element is the remainder as a string. + + + + + &reftitle.errors; + + This function throws a ValueError in the following cases: + + num1 or num2 is not a well-formed BCMath numeric string + scale is outside the valid range + + + + This function throws a DivisionByZeroError exception if num2 + is 0. + + + + + &reftitle.examples; + + <function>bcdivmod</function> example + + +]]> + + + + <function>bcdivmod</function> with decimals + + +]]> + + + + + + &reftitle.seealso; + + + bcdiv + bcmod + + + + + diff --git a/reference/bc/functions/bcfloor.xml b/reference/bc/functions/bcfloor.xml new file mode 100644 index 000000000000..068f0ef2cba3 --- /dev/null +++ b/reference/bc/functions/bcfloor.xml @@ -0,0 +1,91 @@ + + + + + bcfloor + Round arbitrary precision number fractions down + + + + &reftitle.description; + + stringbcfloor + stringnum + + + Returns the next lowest integer value by rounding down + num if necessary. + + + + + &reftitle.parameters; + + + + num + + + The value to round. + + + + + + + + + &reftitle.returnvalues; + + num rounded down to the next lowest number as a string. + + + + + &reftitle.examples; + + + <function>ceil</function> example + + +]]> + + + + + + + &reftitle.seealso; + + + bcceil + bcround + + + + + diff --git a/reference/bc/functions/bcmod.xml b/reference/bc/functions/bcmod.xml index 399bda9967b1..aa24c38c2224 100644 --- a/reference/bc/functions/bcmod.xml +++ b/reference/bc/functions/bcmod.xml @@ -125,6 +125,7 @@ echo bcmod('5.7', '1.3'); // 0.5 as of PHP 7.2.0; 0 previously bcdiv + bcdivmod diff --git a/reference/bc/functions/bcround.xml b/reference/bc/functions/bcround.xml new file mode 100644 index 000000000000..ce55db84f5c5 --- /dev/null +++ b/reference/bc/functions/bcround.xml @@ -0,0 +1,316 @@ + + + + + bcround + Rounds a arbitrary precision number + + + + &reftitle.description; + + stringbcround + stringnum + intprecision0 + RoundingModemodeRoundingMode::HalfAwayFromZero + + + Returns the rounded value of num to + specified precision + (number of digits after the decimal point). + precision can also be negative or zero (default). + + + + + &reftitle.parameters; + + + + num + + + The value to round. + + + + + precision + + + The optional number of decimal digits to round to. + + + If the precision is positive, num is + rounded to precision significant digits after the decimal point. + + + If the precision is negative, num is + rounded to precision significant digits before the decimal point, + i.e. to the nearest multiple of pow(10, -$precision), e.g. for a + precision of -1 num is rounded to tens, + for a precision of -2 to hundreds, etc. + + + + + mode + + + Specifies the rounding mode. + + + + + + + + + &reftitle.returnvalues; + + The value rounded to the given precision, as a string. + + + + + &reftitle.examples; + + + <function>bcround</function> examples + + +]]> + + &example.outputs; + + + + + + + + <parameter>precision</parameter> examples + + +]]> + + &example.outputs; + + + + + + + + <parameter>mode</parameter> examples + + +]]> + + &example.outputs; + + + + + + + + <parameter>mode</parameter> with <parameter>precision</parameter> examples + + +]]> + + &example.outputs; + + + + + + + + + &reftitle.seealso; + + + bcceil + bcfloor + + + + + diff --git a/reference/bc/versions.xml b/reference/bc/versions.xml index 2a8865130fd4..5a85d801a5e6 100644 --- a/reference/bc/versions.xml +++ b/reference/bc/versions.xml @@ -5,12 +5,16 @@ --> + + + + From 2e7b63addf8bec367d57c237bd744434f336d6c2 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Sat, 23 Nov 2024 19:29:16 +0900 Subject: [PATCH 02/12] Remove unnecessary para and use exceptionname --- reference/bc/functions/bcdivmod.xml | 44 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/reference/bc/functions/bcdivmod.xml b/reference/bc/functions/bcdivmod.xml index 95831fd14ae1..58671c3d71a3 100644 --- a/reference/bc/functions/bcdivmod.xml +++ b/reference/bc/functions/bcdivmod.xml @@ -22,27 +22,25 @@ &reftitle.parameters; - - - - num1 - - - The dividend, as a string. - - - - - num2 - - - The divisor, as a string. - - - - &bc.scale.description; - - + + + num1 + + + The dividend, as a string. + + + + + num2 + + + The divisor, as a string. + + + + &bc.scale.description; + @@ -56,14 +54,14 @@ &reftitle.errors; - This function throws a ValueError in the following cases: + This function throws a ValueError in the following cases: num1 or num2 is not a well-formed BCMath numeric string scale is outside the valid range - This function throws a DivisionByZeroError exception if num2 + This function throws a DivisionByZeroError exception if num2 is 0. From 1d6867287ee08f49dee21c88f3f1eae65ea09769 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Sat, 23 Nov 2024 21:13:26 +0900 Subject: [PATCH 03/12] Address comments --- reference/bc/functions/bcceil.xml | 44 ++++---- reference/bc/functions/bcdivmod.xml | 14 ++- reference/bc/functions/bcfloor.xml | 44 ++++---- reference/bc/functions/bcround.xml | 156 +++++++++++++--------------- 4 files changed, 116 insertions(+), 142 deletions(-) diff --git a/reference/bc/functions/bcceil.xml b/reference/bc/functions/bcceil.xml index d95b07847740..ca2084426b7a 100644 --- a/reference/bc/functions/bcceil.xml +++ b/reference/bc/functions/bcceil.xml @@ -20,18 +20,16 @@ &reftitle.parameters; - - - - num - - - The value to round. - - - - - + + + num + + + The value to round. + + + + @@ -43,10 +41,9 @@ &reftitle.examples; - - - <function>ceil</function> example - + + <function>ceil</function> example + ]]> - - - + + &reftitle.seealso; - - - bcfloor - bcround - - + + bcfloor + bcround + - + bcround Rounds a arbitrary precision number @@ -14,50 +14,25 @@ intprecision0 RoundingModemodeRoundingMode::HalfAwayFromZero - + Returns the rounded value of num to specified precision (number of digits after the decimal point). precision can also be negative or zero (default). - + &reftitle.parameters; - - num - - - The value to round. - - - - - precision - - - The optional number of decimal digits to round to. - - - If the precision is positive, num is - rounded to precision significant digits after the decimal point. - - - If the precision is negative, num is - rounded to precision significant digits before the decimal point, - i.e. to the nearest multiple of pow(10, -$precision), e.g. for a - precision of -1 num is rounded to tens, - for a precision of -2 to hundreds, etc. - - - + + mode - + Specifies the rounding mode. - + @@ -65,9 +40,9 @@ &reftitle.returnvalues; - - The value rounded to the given precision, as a string. - + + Returns a BCMath string number representing num rounded to the given precision. + @@ -139,7 +114,9 @@ string(1) "0" - <parameter>mode</parameter> examples + + Example of using <function>bcround</function> with different <parameter>mode</parameter> values + - <parameter>mode</parameter> with <parameter>precision</parameter> examples + + Example of using <function>bcround</function> with different <parameter>mode</parameter> values + when specifying <parameter>precision</parameter> + Date: Sun, 24 Nov 2024 22:29:38 +0900 Subject: [PATCH 07/12] address a comment Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com> --- reference/bc/functions/bcceil.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/functions/bcceil.xml b/reference/bc/functions/bcceil.xml index 1a70e4002e72..46faf08938e7 100644 --- a/reference/bc/functions/bcceil.xml +++ b/reference/bc/functions/bcceil.xml @@ -35,7 +35,7 @@ &reftitle.returnvalues; - Returns a BCMath string number representing num rounded up to the nearest integer. + Returns a numeric string representing num rounded up to the nearest integer. From 11c77a940118bad9ff7183b49546f1d76c16653e Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:29:46 +0900 Subject: [PATCH 08/12] address a comment Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com> --- reference/bc/functions/bcfloor.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/functions/bcfloor.xml b/reference/bc/functions/bcfloor.xml index 37f6bab4d3b7..bcf02fe45d3e 100644 --- a/reference/bc/functions/bcfloor.xml +++ b/reference/bc/functions/bcfloor.xml @@ -35,7 +35,7 @@ &reftitle.returnvalues; - Returns a BCMath string number representing num rounded down to the nearest integer. + Returns a numeric string representing num rounded down to the nearest integer. From 77df1ae502ed6eda95f7587769c610ae49be41c8 Mon Sep 17 00:00:00 2001 From: Saki Takamachi <34942839+SakiTakamachi@users.noreply.github.com> Date: Sun, 24 Nov 2024 22:29:55 +0900 Subject: [PATCH 09/12] address a comment Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com> --- reference/bc/functions/bcround.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/bc/functions/bcround.xml b/reference/bc/functions/bcround.xml index c4f0e9698f61..34b55048e6a5 100644 --- a/reference/bc/functions/bcround.xml +++ b/reference/bc/functions/bcround.xml @@ -41,7 +41,7 @@ &reftitle.returnvalues; - Returns a BCMath string number representing num rounded to the given precision. + Returns a numeric string representing num rounded to the given precision. From 3d93dcec28151eef20a31520d45cefdb92d68703 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Sun, 24 Nov 2024 23:27:44 +0900 Subject: [PATCH 10/12] Address comments --- reference/bc/functions/bcceil.xml | 2 +- reference/bc/functions/bcfloor.xml | 2 +- reference/bc/functions/bcround.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reference/bc/functions/bcceil.xml b/reference/bc/functions/bcceil.xml index 46faf08938e7..e88bd7d5ec06 100644 --- a/reference/bc/functions/bcceil.xml +++ b/reference/bc/functions/bcceil.xml @@ -3,7 +3,7 @@ bcceil - Round arbitrary precision number fractions up + Round up arbitrary precision number diff --git a/reference/bc/functions/bcfloor.xml b/reference/bc/functions/bcfloor.xml index bcf02fe45d3e..9235507e17ed 100644 --- a/reference/bc/functions/bcfloor.xml +++ b/reference/bc/functions/bcfloor.xml @@ -3,7 +3,7 @@ bcfloor - Round arbitrary precision number fractions down + Round down arbitrary precision number diff --git a/reference/bc/functions/bcround.xml b/reference/bc/functions/bcround.xml index 34b55048e6a5..a5ffa6acaa3e 100644 --- a/reference/bc/functions/bcround.xml +++ b/reference/bc/functions/bcround.xml @@ -3,7 +3,7 @@ bcround - Rounds a arbitrary precision number + Round arbitrary precision number From 501f4d9f7eb50509c19a4e979addf73670778916 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 25 Nov 2024 08:09:29 +0900 Subject: [PATCH 11/12] use vardump() for example --- reference/bc/functions/bcceil.xml | 14 +++++++++++--- reference/bc/functions/bcfloor.xml | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/reference/bc/functions/bcceil.xml b/reference/bc/functions/bcceil.xml index e88bd7d5ec06..d2e9be85e986 100644 --- a/reference/bc/functions/bcceil.xml +++ b/reference/bc/functions/bcceil.xml @@ -46,12 +46,20 @@ ]]> + &example.outputs; + + + diff --git a/reference/bc/functions/bcfloor.xml b/reference/bc/functions/bcfloor.xml index 9235507e17ed..8ed28a46e60b 100644 --- a/reference/bc/functions/bcfloor.xml +++ b/reference/bc/functions/bcfloor.xml @@ -46,12 +46,20 @@ ]]> + &example.outputs; + + + From 5ff4071e1a6f0370fb8c10711e711e88dd3bd8d0 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 25 Nov 2024 08:16:18 +0900 Subject: [PATCH 12/12] Added bcdivmod in bcdiv's seealso --- reference/bc/functions/bcdiv.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/reference/bc/functions/bcdiv.xml b/reference/bc/functions/bcdiv.xml index 685dc5e437fe..b3fb36be4282 100644 --- a/reference/bc/functions/bcdiv.xml +++ b/reference/bc/functions/bcdiv.xml @@ -95,6 +95,7 @@ echo bcdiv('105', '6.55957', 3); // 16.007 &reftitle.seealso; + bcdivmod bcmod bcmul