rfc:intdiv

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:intdiv [2014/07/15 00:03]
ajf Indentation matters?
rfc:intdiv [2017/09/22 13:28] (current)
Line 1: Line 1:
 ====== PHP RFC: intdiv() ====== ====== PHP RFC: intdiv() ======
-  * Version: 0.1 +  * Version: 0.2 
-  * Date: 2014-07-15+  * Date: 2014-07-15 ​(Last updated 2014-07-16)
   * Author: Andrea Faulds, ajf@ajf.me   * Author: Andrea Faulds, ajf@ajf.me
-  * Status: ​Under Discussion+  * Status: ​Accepted (Fallback proposal; operator rejected), merged into master
   * First Published at: http://​wiki.php.net/​rfc/​intdiv   * First Published at: http://​wiki.php.net/​rfc/​intdiv
  
Line 13: Line 13:
 ===== Proposal ===== ===== Proposal =====
  
-A new function is added to ext/​standard'​s math functions:+new infix operator is added: 
 + 
 +<code php> 
 +var_dump(3 %% 2); // int(1) 
 +</​code>​ 
 + 
 +It returns the integer division of the first operand by the second. If the divisor (the second operand) is zero, it throws an E_WARNING and returns FALSE, just as the division operator does. If the first operator is ''​LONG_MIN''​ (''​-PHP_INT_MAX - 1''​) and the second is ''​-1'',​ it returns zero, much like the ''​%''​ operator. 
 + 
 +Assignment is also supported:​ 
 + 
 +<code php> 
 +$foobar = 3; 
 +$foobar %%= 2; 
 +var_dump($foobar);​ // int(1) 
 +</​code>​ 
 + 
 +==== Fallback proposal ==== 
 + 
 +The original proposal was just to add a function. Should the operator fail to get in, I instead propose a new function is added to ext/​standard'​s math functions:
  
 <code php> <code php>
 intdiv(int $numerator, int $divisor) intdiv(int $numerator, int $divisor)
-</​code ​php>+</​code>​
  
-It returns the integer division of //​$numerator//​ by //​$divisor//​. If //​$divisor//​ is zero, it throws an E_WARNING and returns FALSE, just as the division operator does.+It returns the integer division of //​$numerator//​ by //​$divisor//​. If //​$divisor//​ is zero, it throws an E_WARNING and returns FALSE, just as the division operator does. If the first operator is ''​LONG_MIN''​ (''​-PHP_INT_MAX - 1''​) and the second is ''​-1'',​ it returns zero, much like the ''​%''​ operator.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-It would conflict with any existing userland functions called intdiv, but that's unlikely.+The ''​%''''​%''​ operator wouldn'​t conflict with anything. 
 + 
 +The fallback proposal, ''​intdiv'', ​would conflict with any existing userland functions called intdiv, but that's unlikely.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 29: Line 49:
 Next PHP 5.x (i.e. PHP 5.7). Next PHP 5.x (i.e. PHP 5.7).
  
-===== RFC Impact and Unaffected PHP Functionality ​=====+===== Future Scope =====
  
-It's just a function, it has no internals or wider impact.+None I can see.
  
-===== Future Scope =====+===== Vote =====
  
-Should we make it shorter, just //div()//? That done, should we make it an internal function with its own opcode, much like //pow()//? In that case, why not make it an infix operator, e.g. ''​3 div 2''?​ Game Maker Language does this, as I noted in References.+Two votes are being held simultaneously:​
  
-===== Proposed Voting Choices =====+  - Merge the intdiv operator (''​%''''​%''​) patch into master? Yes/No (requires 2/3 majority, language change) 
 +  - If the ''​%''''​%''​ operator vote fails to achieve a 2/3 majority, should the intdiv() function patch be merged into master? Yes/No (requires 50%+1 majority, non-language change)
  
-This is not language changeso 50%+1 Yes/No to merge into master.+As the ext/​standard function ​is to be considered ​fallback option onlyit would not be merged if the proper operator gets in. 
 + 
 +Voting opened 2014-07-30 and ended 2014-08-06. 
 + 
 +<doodle title="​Merge the intdiv operator patch into master?"​ auth="​ajf"​ voteType="​single"​ closed="​true">​ 
 +   ​* ​Yes 
 +   ​* ​No 
 +</​doodle>​ 
 + 
 +---- 
 + 
 +<doodle title="​If the operator vote fails to achieve a 2/3 majority, should the intdiv() function patch be merged ​into master?" auth="​ajf"​ voteType="​single"​ closed="​true">​ 
 +   * Yes 
 +   * No 
 +</​doodle>​
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
  
-A fully-working patch against master with tests has been made. The pull request is here: https://​github.com/​php/​php-src/​pull/​722+A fully-working patch against master with tests has been made. The pull request ​is here: https://​github.com/​php/​php-src/​pull/​724 
 + 
 +The pull request for the fallback (and original proposal) of just the //​ext/​standard//​ function ​is here: https://​github.com/​php/​php-src/​pull/​722
  
 ===== Implementation ===== ===== Implementation =====
-After the project is implemented,​ this section should contain ​ + 
-  - the version(s) it was merged ​to +It was merged ​into master here: https://​github.com/​php/​php-src/commit/​8e964fe665b6a4fbdc59639dad2efb4cd43d1c05 
-  ​a link to the git commit(s) + 
-  - a link to the PHP manual ​entry for the feature+It will be in PHP 7. Since there is no 5.7 branch, it is doubtful it will actually be in 5.7. 
 + 
 +PHP Manual - http://​php.net/​manual/​en/​function.intdiv.php
  
 ===== References ===== ===== References =====
  
-Somewhat inspired by Python'​s ''//''​ operator, and the equivalent //div// operator in Game Maker Language (a somewhat obscure C-like partially object-oriented scripting language).+Somewhat inspired by Python'​s ''/​''''​/''​ operator, and the equivalent //div// operator in Pascal and Game Maker Language (a somewhat obscure C-like partially object-oriented scripting language, which probably inherited this from Pascal). The choice of the ''​%''''​%''​ syntax is thanks to Bishop Bettini'​s suggestion on internals.
  
 ===== Rejected Features ===== ===== Rejected Features =====
  
 None yet. None yet.
 +
 +===== Changelog =====
 +
 +  * 0.2 - Propose ''​%''''​%''​ operator instead
 +  * 0.1 - Created, intdiv() function
rfc/intdiv.1405382624.txt.gz · Last modified: 2017/09/22 13:28 (external edit)