rfc:adding_bcround_bcfloor_bcceil_to_bcmath
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:adding_bcround_bcfloor_bcceil_to_bcmath [2023/10/01 11:27] – created saki | rfc:adding_bcround_bcfloor_bcceil_to_bcmath [2023/11/30 08:21] (current) – saki | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Adding bcround, bcfloor and bcceil to BCMath ====== | ====== PHP RFC: Adding bcround, bcfloor and bcceil to BCMath ====== | ||
- | * Version: 0.9 | + | * Version: 0.1.0 |
* Date: 2023-10-01 | * Date: 2023-10-01 | ||
* Author: Saki Takamachi, saki@sakiot.com | * Author: Saki Takamachi, saki@sakiot.com | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | As you know, BCMath is an arbitrary precision mathematical function that supports exact calculations. As of the writing of this RFC, nine calculation functions exist, but no equivalents exist for round, floor, and ceil. Considering the role of BCMath, | + | As you know, BCMath is an arbitrary precision mathematical function that supports exact calculations. As of the writing of this RFC, nine calculation functions exist, but no equivalents exist for round, floor, and ceil. Considering the role of BCMath, |
===== Proposal ===== | ===== Proposal ===== | ||
This RFC proposes to introduce three new functions to BCMath: bcround(), bcfloor(), and bcceil(). It is assumed that the usage will be the same as round(), floor(), and ceil(), except that the value passed to the argument and the return value will be of string type. | This RFC proposes to introduce three new functions to BCMath: bcround(), bcfloor(), and bcceil(). It is assumed that the usage will be the same as round(), floor(), and ceil(), except that the value passed to the argument and the return value will be of string type. | ||
- | To [[http:// | + | < |
- | for inclusion in one of the world' | + | var_dump(bcround(' |
+ | // string(4) "0.29" | ||
- | Remember that the RFC contents should be easily reusable in the PHP Documentation. | + | var_dump(bcfloor(' |
+ | // string(2) " | ||
- | If applicable, you may wish to use the language specification | + | var_dump(bcceil(' |
+ | // string(2) " | ||
+ | </ | ||
+ | |||
+ | Since it is an arbitrary precision calculation, there is no need to consider the maximum value of int or double. | ||
+ | |||
+ | < | ||
+ | var_dump(bcround(' | ||
+ | // string(30) " | ||
+ | |||
+ | var_dump(bcfloor(' | ||
+ | // string(30) " | ||
+ | |||
+ | var_dump(bcceil(' | ||
+ | // string(30) " | ||
+ | </ | ||
+ | |||
+ | ==== Round mode constant ==== | ||
+ | Similar to round(), we can specify how edge cases are handled using mode. I plan to use the constants for round() included in standard ext as they are. The reason for reusing standard ext constants is as follows. | ||
+ | |||
+ | * standard ext is installed by default | ||
+ | * It is not a constant that expresses a complex concept enough to prepare a new constant for BCMath | ||
+ | * Having multiple similar constants is unfriendly | ||
+ | * These constants do not change frequently, and reusing them does not impede maintenance | ||
+ | |||
+ | ==== Ignore BCMath scale ==== | ||
+ | BCMath allows you to specify the scale of calculation results. You can pass values to arguments on a per-function basis, or you can set default values for BCMath and omit arguments. | ||
+ | |||
+ | Due to their nature, there is no point in setting the scale of the three functions proposed this time. Therefore, these functions ignore scale settings both semantically and implementationally. | ||
+ | |||
+ | You might think that it can be used to specify the precision of round, but scale does not accept negative values. This cannot be used because precision must accept negative values. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | What breaks, | + | These are new features |
+ | |||
+ | If I had to point out my concerns, I would say that code that satisfies | ||
+ | |||
+ | * A situation where the user has defined a function with the same name, such as bcround() | ||
+ | * And, the existence of the function is not checked in advance. | ||
+ | However, I do not think it is necessary to consider these matters. | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | List the proposed PHP versions that the feature will be included in. Use relative versions such as "next PHP 8.x" or "next PHP 8.x.y". | + | next PHP 8.x (Probably |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
==== To SAPIs ==== | ==== To SAPIs ==== | ||
- | Describe the impact to CLI, Development web server, embedded PHP etc. | + | |
+ | None. | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | Will existing extensions be affected? | + | |
+ | Only BCMath is affected. | ||
==== To Opcache ==== | ==== To Opcache ==== | ||
- | It is necessary to develop RFC's with opcache in mind, since opcache is a core extension distributed with PHP. | ||
- | Please explain how you have verified your RFC's compatibility with opcache. | + | No impact. |
==== New Constants ==== | ==== New Constants ==== | ||
- | Describe any new constants so they can be accurately and comprehensively explained in the PHP documentation. | + | |
+ | None. | ||
==== php.ini Defaults ==== | ==== php.ini Defaults ==== | ||
- | If there are any php.ini settings then list: | + | |
- | * hardcoded default values | + | None. |
- | * php.ini-development values | + | |
- | * php.ini-production values | + | |
===== Open Issues ===== | ===== Open Issues ===== | ||
- | Make sure there are no open issues when the vote starts! | + | |
+ | None. | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
- | List existing areas/ | ||
- | This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise. | + | There is no effect on anything other than BCMath. |
===== Future Scope ===== | ===== Future Scope ===== | ||
- | This section details areas where the feature might be improved in future, but that are not currently proposed in this RFC. | + | None. |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Include these so readers know where you are heading and can discuss | + | |
+ | As per the voting | ||
+ | Voting started on 2023-11-15 and will end on 2023-11-30 00:00 GMT. | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | Links to any external patches and tests go here. | ||
- | If there is no patch, make it clear who will create | + | I am currently creating |
- | Make it clear if the patch is intended to be the final patch, or is just a prototype. | + | ===== Implementation ===== |
+ | Yet. | ||
- | For changes affecting the core language, you should also provide a patch for the language specification. | + | ===== Rejected Features ===== |
- | ===== Implementation ===== | + | None. |
- | After the project is implemented, | + | |
- | - the version(s) it was merged into | + | |
- | - a link to the git commit(s) | + | |
- | - a link to the PHP manual entry for the feature | + | |
- | - a link to the language specification section (if any) | + | |
===== References ===== | ===== References ===== | ||
- | Links to external references, discussions or RFCs | ||
- | ===== Rejected Features | + | https:// |
- | Keep this updated with features that were discussed on the mail lists. | + | https:// |
+ | https:// | ||
+ | https:// | ||
+ | |||
+ | ===== Changelog | ||
+ | |||
+ | * 0.1.0: created rfc |
rfc/adding_bcround_bcfloor_bcceil_to_bcmath.1696159631.txt.gz · Last modified: 2023/10/01 11:27 by saki