Skip to content

Conversation

@liborm85
Copy link
Contributor

PR fixed bug #46564 in bcmod. Now is supported decimal number.

This bug is not in 3rd party library (as write in ticket), but is in PHP.

@smalyshev smalyshev added the Bug label Oct 17, 2015
@smalyshev
Copy link
Contributor

It would be nice to add a test for this.

@liborm85
Copy link
Contributor Author

Test added.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get this - how comes bcmod returns non-integer? I always thought module operation always returns integer. Also, 3.5 % 4 returns 3, so I don't see why BC version should be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Operator % probably calculate only with integer. But for example function fmod calculate with floats numbers. Example: fmod(3.5, 4) returns 3.5. Why is diference between fmod and bcmod...?

Example on wolfram aplha: http://www.wolframalpha.com/input/?i=3.5+mod+4

@liborm85
Copy link
Contributor Author

liborm85 commented Jan 5, 2016

Who needs correct calculation modulo without bugfix in PHP, can use:

function modulo($number, $modulus) {
  return bcsub($number, bcmul(bcdiv($number, $modulus, 0), $modulus));
}

bcscale(1);
var_dump(modulo("3.5", "4"));  // 3.5
var_dump(modulo("1071", "357.5")); // 356.0

@krakjoe
Copy link
Member

krakjoe commented Jan 6, 2017

@liborm85 can this be rebased on current master please ?

@nikic this is okay for 7.2, right ?

@liborm85
Copy link
Contributor Author

liborm85 commented Jan 6, 2017

@krakjoe Done.

@nikic nikic self-assigned this Jan 6, 2017
@nikic
Copy link
Member

nikic commented Jan 6, 2017

This change looks fine to me, but I'm slightly concerned about the BC impact this might have. Code may rely on the current behavior :/

@krakjoe
Copy link
Member

krakjoe commented Jan 6, 2017

@nikic there's plenty of time for an RFC for 7.2, think that's best ?

@nikic
Copy link
Member

nikic commented Jan 6, 2017

I don't think an RFC is worthwhile for such a minor change. This is a "bug fix with potential BC impact", not a new feature or an intentional BC break.

I'm inclined to just merge this with an UPGRADING note and see if anyone complains.

@krakjoe
Copy link
Member

krakjoe commented Jan 6, 2017

Oh, yeah, UPGRADING is a must.

I was quite comfortable with it in 7.2 anyway, so long as no major objections.

@nikic
Copy link
Member

nikic commented Jan 7, 2017

Merged via 90dcbbe with a note in UPGRADING. Thanks!

Interestingly, bcmod() already behaved correctly in HHVM :)

@nikic nikic closed this Jan 7, 2017
@liborm85 liborm85 deleted the bug46564 branch July 11, 2017 15:11
@cmb69 cmb69 mentioned this pull request Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants