rfc:intdiv
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:intdiv [2014/07/15 00:13] – Fixed formatting ajf | rfc:intdiv [2014/09/16 19:08] – Wait oops ajf | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: intdiv() ====== | ====== PHP RFC: intdiv() ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
- | * Date: 2014-07-15 | + | * Date: 2014-07-15 |
* Author: Andrea Faulds, ajf@ajf.me | * Author: Andrea Faulds, ajf@ajf.me | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 13: | Line 13: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | A new function is added to ext/ | + | A new infix operator is added: |
+ | |||
+ | <code php> | ||
+ | var_dump(3 %% 2); // int(1) | ||
+ | </ | ||
+ | |||
+ | 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 '' | ||
+ | |||
+ | Assignment is also supported: | ||
+ | |||
+ | <code php> | ||
+ | $foobar = 3; | ||
+ | $foobar %%= 2; | ||
+ | var_dump($foobar); | ||
+ | </ | ||
+ | |||
+ | ==== 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/ | ||
<code php> | <code php> | ||
Line 19: | Line 37: | ||
</ | </ | ||
- | It returns the integer division of // | + | It returns the integer division of // |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | It would conflict with any existing userland functions called intdiv, but that's unlikely. | + | The '' |
+ | |||
+ | The fallback proposal, '' | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 31: | Line 51: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
- | 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. '' | + | None I can see. |
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | This is not a language change, | + | Two votes are being held simultaneously: |
+ | |||
+ | - Merge the intdiv operator ('' | ||
+ | - If the '' | ||
+ | |||
+ | As the ext/standard function is to be considered a fallback option only, it would not be merged if the proper operator gets in. | ||
+ | |||
+ | Voting opened 2014-07-30 and ended 2014-08-06. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | A fully-working patch against master with tests has been made. The pull request is here: https:// | + | A fully-working patch against master with tests has been made. The pull request |
+ | |||
+ | The pull request for the fallback (and original proposal) of just the // | ||
===== Implementation ===== | ===== Implementation ===== | ||
Line 49: | Line 90: | ||
===== References ===== | ===== References ===== | ||
- | Somewhat inspired by Python' | + | Somewhat inspired by Python' |
===== Rejected Features ===== | ===== Rejected Features ===== | ||
None yet. | None yet. | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * 0.2 - Propose '' | ||
+ | * 0.1 - Created, intdiv() function |
rfc/intdiv.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1