rfc:pow-operator
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:pow-operator [2013/12/18 08:39] – [Introduction] datibbaw | rfc:pow-operator [2014/08/11 18:24] – nikic | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Power Operator ====== | ====== PHP RFC: Power Operator ====== | ||
- | * Version: 0.1 | + | * Version: 0.3 |
* Date: 2013-11-23 | * Date: 2013-11-23 | ||
* Author: Tjerk Meesters, datibbaw@php.net | * Author: Tjerk Meesters, datibbaw@php.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
+ | * Revision (0.1 → 0.2): 2013-12-19 | ||
+ | * Revision (0.2 → 0.3): 2013-12-21 | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This proposal is three-fold: | + | This proposal is two-fold: |
- | - Turn the existing [[http:// | + | - Introduce an exponential |
* Avoids a function call. | * Avoids a function call. | ||
* Support for [[rfc: | * Support for [[rfc: | ||
- | - Introduce an exponential (right associative) operator ''< | ||
* Easier to read and shorter to write. | * Easier to read and shorter to write. | ||
* Can be found in other languages. | * Can be found in other languages. | ||
- | - For completion, introduce | + | - Introduce |
===== Proposal ===== | ===== Proposal ===== | ||
- | |||
- | **pow() as language construct** | ||
- | |||
- | No changes to existing code, safe for one: | ||
- | |||
- | <code php> | ||
- | var_dump(pow([], | ||
- | </ | ||
- | |||
- | **Power operator** | ||
A short working example: | A short working example: | ||
Line 64: | Line 55: | ||
The operator precedence is: | The operator precedence is: | ||
- | * higher than the bitwise not (~) and | + | * higher than the bitwise not (~) and unary minus, |
- | * lower than array dereferencing. | + | * lower than array dereferencing. |
Examples: | Examples: | ||
Line 72: | Line 63: | ||
echo 2 ** 3 ** 2; // 512 (not 64) | echo 2 ** 3 ** 2; // 512 (not 64) | ||
echo -3 ** 2; // -9 (not 9) | echo -3 ** 2; // -9 (not 9) | ||
+ | echo 1 - 3 ** 2; // -8 | ||
echo ~3 ** 2; // -10 (not 16) | echo ~3 ** 2; // -10 (not 16) | ||
</ | </ | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | 21-Dec-2013: | ||
+ | * Removed turning pow() into a language construct from the proposal, due to BC breaks. | ||
+ | * Closed vote and moved RFC back to Discussion status. | ||
+ | * Reverted commit [[https:// | ||
+ | |||
+ | 22-Dec-2013: | ||
+ | * Moved RFC back to Voting status | ||
===== Discussion ===== | ===== Discussion ===== | ||
- | > Shouldn' | + | > Should |
- | This would be possible by giving | + | According to the following resources, the scale tips more towards having the exponent precede the unary minus: |
- | <code php> | + | |
- | -3 ** 2 // 9 | + | * http://math.stackexchange.com/ |
- | 1 -3 ** 2 // -8 | + | * http:// |
- | </code> | + | |
- | However, the bare notation violates mathematical laws and thus will not be added to the proposal. | + | **Similar languages** |
+ | |||
+ | * Ada | ||
+ | * D | ||
+ | * F# | ||
+ | * Fortran | ||
+ | * Freemat | ||
+ | * Haskell | ||
+ | * Mathematica / Matlab / Scilab | ||
+ | * Octave | ||
+ | * Perl | ||
+ | * Python | ||
+ | * R | ||
+ | * Ruby | ||
+ | * Sage | ||
+ | * VB / Basic | ||
+ | |||
+ | **Dissimilar languages** | ||
+ | |||
+ | * Bash | ||
+ | * Cobol | ||
+ | * ColdFusion | ||
+ | * Excel | ||
+ | * Tcl | ||
---- | ---- | ||
Line 100: | Line 124: | ||
* Octave | * Octave | ||
* Matlab | * Matlab | ||
- | * D | ||
* ColdFusion | * ColdFusion | ||
** Languages with right associative exponential operator** | ** Languages with right associative exponential operator** | ||
+ | * D | ||
* Haskell | * Haskell | ||
* R | * R | ||
Line 141: | Line 165: | ||
External extensions such as [[http:// | External extensions such as [[http:// | ||
- | ===== Open Issues ===== | + | ===== Vote ===== |
- | + | ||
- | None. | + | |
- | + | ||
- | + | ||
- | ===== Proposed Voting Choices | + | |
Voting will be based on the following: | Voting will be based on the following: | ||
- | * Turn '' | ||
* Add the power operators ''< | * Add the power operators ''< | ||
* Add '' | * Add '' | ||
+ | |||
+ | Changes from 0.1: | ||
+ | |||
+ | * A option is added to vote for a non-associative ''< | ||
+ | |||
+ | A two third majority is required for acceptance. | ||
---- | ---- | ||
- | <doodle title=" | + | <doodle title=" |
- | * Yes | + | * Yes, right associative |
+ | * Yes, non associative | ||
* No | * No | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | Voting ends on 5th of January 2014. | ||
+ | |||
+ | |||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
Line 165: | Line 196: | ||
Power operator PR: https:// | Power operator PR: https:// | ||
+ | PHP 5.6 Commits: [[http:// |
rfc/pow-operator.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1