rfc:adding_bcround_bcfloor_bcceil_to_bcmath

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:adding_bcround_bcfloor_bcceil_to_bcmath [2023/10/01 11:27] – created sakirfc: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: Draft+  * Status: Accepted
   * First Published at: https://wiki.php.net/rfc/adding_bcround_bcfloor_bcceil_to_bcmath   * First Published at: https://wiki.php.net/rfc/adding_bcround_bcfloor_bcceil_to_bcmath
  
 ===== 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, I believe it is better to support functions like these.+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, supporting features like these is important.
  
 ===== 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://news.php.net/php.internals/66051|paraphrase Zeev Suraski]], explain hows the proposal brings substantial value to be considered +<code> 
-for inclusion in one of the world's most popular programming languages.+var_dump(bcround('0.285', 2, PHP_ROUND_HALF_UP)); 
 +// string(4) "0.29"
  
-Remember that the RFC contents should be easily reusable in the PHP Documentation.+var_dump(bcfloor('13.0915')); 
 +// string(2) "13"
  
-If applicableyou may wish to use the language specification as a reference.+var_dump(bcceil('24.00001')); 
 +// string(2) "25" 
 +</code> 
 + 
 +Since it is an arbitrary precision calculationthere is no need to consider the maximum value of int or double. 
 + 
 +<code> 
 +var_dump(bcround('0.12345678901234567890123456789', 28)); 
 +// string(30) "0.1234567890123456789012345679" 
 + 
 +var_dump(bcfloor('123456789012345678901234567890.5')); 
 +// string(30) "123456789012345678901234567890" 
 + 
 +var_dump(bcceil('123456789012345678901234567890.5')); 
 +// string(30) "123456789012345678901234567891" 
 +</code> 
 + 
 +==== 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 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, and what is the justification for it?+These are new features and do not break existing functionality. 
 + 
 +If I had to point out my concerns, I would say that code that satisfies the following conditions will cause an error to occur. 
 + 
 +  * 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 8.4)
  
 ===== 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/features of PHP that will not be changed by the RFC. 
  
-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 the proposed voting options.+ 
 +As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. 
 +Voting started on 2023-11-15 and will end on 2023-11-30 00:00 GMT. 
 +<doodle title="Adding bcround, bcfloor and bcceil to BCMath" auth="Saki Takamachi" voteType="single" closed="false" closeon="2023-11-30T00:00:00Z"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== 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 patch, or whether a volunteer to help with implementation is needed.+I am currently creating prototype.
  
-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, this section should contain  +
-  - 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://www.php.net/manual/en/book.bc.php 
-Keep this updated with features that were discussed on the mail lists.+https://www.php.net/manual/en/function.round.php 
 +https://www.php.net/manual/en/function.floor.php 
 +https://www.php.net/manual/en/function.ceil.php 
 + 
 +===== 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