Skip to content

Update gmp+bcmath parameter names #6205

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

Closed
wants to merge 3 commits into from
Closed

Update gmp+bcmath parameter names #6205

wants to merge 3 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Sep 24, 2020

GMP doesn't have much in terms of meaningful parameter names... I went with num1/num2 in favor of a, b.

@nikic nikic requested a review from kocsismate September 24, 2020 13:30
@nikic nikic changed the title Update gmp parameter names Update gmp+bcmath parameter names Sep 24, 2020
@nikic
Copy link
Member Author

nikic commented Sep 24, 2020

Okay, I just looked at ext/bcmath as well, and realized that it would make sense to consider these two extensions together, as there's a good bit of overlap.

bcmath uses $left_operand and $right_operand in places, so $lhs/$rhs, $left/$right might be possibilities instead of $num1/$num2. However, this doesn't generalize, e.g. speaking about a left and a right hand side of a Legendre symbol makes little sense (it would be more like, top and bottom).

bcmath also uses $dividend and $divisor for divisions in particular. I'm not fond of that, because I always forget which one is which.


function gmp_mod(GMP|int|string $a, GMP|int|string $b): GMP {}
function gmp_mod(GMP|int|string $num1, GMP|int|string $num2): GMP {}
Copy link
Member

@Girgias Girgias Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function gmp_mod(GMP|int|string $num1, GMP|int|string $num2): GMP {}
function gmp_mod(GMP|int|string $num, GMP|int|string $mod): GMP {}

To align with BCMath?
EDIT: Got confused by bcpowmod()

@Girgias
Copy link
Member

Girgias commented Sep 24, 2020

Okay, I just looked at ext/bcmath as well, and realized that it would make sense to consider these two extensions together, as there's a good bit of overlap.

bcmath uses $left_operand and $right_operand in places, so $lhs/$rhs, $left/$right might be possibilities instead of $num1/$num2. However, this doesn't generalize, e.g. speaking about a left and a right hand side of a Legendre symbol makes little sense (it would be more like, top and bottom).

I do prefer $num1/$num2 as except for subtraction it's kinda irrelevant what the order is.

bcmath also uses $dividend and $divisor for divisions in particular. I'm not fond of that, because I always forget which one is which.

Maybe using $num and $divisor would make it clearer?


function bcpowmod(string $base, string $exponent, string $modulus, ?int $scale = null): string {}
function bcpowmod(string $base, string $exp, string $mod, ?int $scale = null): string {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I liked $exponent and $modulus a bit more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've restored $exponend/$modulus here and used them on the GMP side as well.


function gmp_rootrem(GMP|int|string $a, int $nth): array {}
function gmp_rootrem(GMP|int|string $num, int $nth): array {}

function gmp_pow(GMP|int|string $base, int $exp): GMP {}
Copy link
Member

@kocsismate kocsismate Sep 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although $base is certainly a good name, but wouldn't it make sense to use $num instead when nearly all the other functions use this term?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. I've switched this to use $num.

@kocsismate
Copy link
Member

Looks good ✅

@php-pulls php-pulls closed this in 2519827 Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants