Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power function as an operator. #543

Merged
merged 1 commit into from Feb 6, 2014
Merged

Conversation

datibbaw
Copy link
Contributor

This PR complements the pow-operator proposal, which has been accepted for 5.6

The power operator allows expressions, like:

echo 2 ** 3; // 8
$x = 2;
echo $x **= 3; // 8

It also supports GMP overloading:

$x = gmp_init(2) ** 3;
var_dump($x instanceof GMP); // bool(true)

@bukka
Copy link
Member

bukka commented Dec 12, 2013

Just quick question! What's the associativity for the gmp overloaded operator?

@bukka
Copy link
Member

bukka commented Dec 12, 2013

Looks like left assoc for gmp and right for num op?

@datibbaw
Copy link
Contributor Author

@bukka Now, you know that doesn't make sense right? An operator doesn't change associativity when the operand types change ;-)

echo gmp_init(2) ** gmp_init(3) ** gmp_init(2); // 512

@bukka
Copy link
Member

bukka commented Dec 12, 2013

yeah my bad!

Fixed recognition of the operator

Added opcode, still doing multiply instead of pow()

opcode now always returns int(42)

The right answer, but always a float

Yanked code from pow() implementation.

Should not handle negative long as exponent ourselves

Added test cases from pow()

Moved precedence higher than '~'

Added GMP operator overloading

Added ZEND_ASSIGN_POW (**=) operator.

Added pow() as a language construct.

Adjusted test cases for changed precedence.

Reduced pow() to shell function around ZEND_API pow_function()

Reduced test case to only contain edge cases
Added overloading test case

Moved unary minus above T_POW

Revert "Added pow() as a language construct."

Bad bad bad idea.

This reverts commit f60b98c.

Reverted unary minus behaviour due to previous revert.
Convert arrays to int(0)
Exponent with array as a base becomes int(0)

Rebase against master

Fixed tokenizer test case
@php-pulls php-pulls merged commit e5ded6e into php:master Feb 6, 2014
@datibbaw datibbaw deleted the pow-operator branch February 6, 2014 13:09
@datibbaw datibbaw restored the pow-operator branch February 6, 2014 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants