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

Use a math library other than moontoast/math #109

Open
ramsey opened this Issue Mar 26, 2016 · 3 comments

Comments

2 participants
@ramsey
Owner

ramsey commented Mar 26, 2016

A math library is not required for this library unless users want to operate on the UUID as a 128-bit integer. For this purpose, the library has suggested moontoast/math as an optional dependency, and internally, this is what ramsey/uuid uses, if it is present. However, moontoast/math is no longer maintained.

I will either create a ramsey/math library that allows the use of different adapters for working with large numbers, or I want to find an existing math library that provides similar functionality.

@ramsey ramsey added this to the Version 4.0.0 milestone Mar 26, 2016

@ramsey

This comment has been minimized.

Owner

ramsey commented Mar 26, 2016

Here's an initial, stubbed-out approach to a ramsey/math library: https://github.com/ramsey/math

Again, I'm not necessarily of the mindset that the math library must be my own. These are just some thoughts I had on how a math library should work.

@oleg-andreyev

This comment has been minimized.

oleg-andreyev commented Sep 11, 2018

@ramsey maybe it's worth using brick/math (or any other library) instead of maintaining own version?

Also I think it would be better to have an ability to set custom math library via FeatureSet and provide "default" BigNumberConverter as it is now.

@ramsey

This comment has been minimized.

Owner

ramsey commented Sep 11, 2018

I'm still giving this a lot of thought. Ideally, ramsey/uuid wouldn't need to know about any external number library at all. I would love to return an unsigned 128-bit integer (or at least 2 unsigned 64-bit integers) and let the caller handle the number by passing it to their preferred library.

To do this, I would need to return the number in string format, since PHP can't handle unsigned 64-bit integers, much less unsigned 128-bit integers. I can do this using bcmath or gmp, but that requires a system dependency, and not everyone has those installed. Likewise, I could use moontoast/math to create this string and return it (as just a string), but again, moontoast/math depends on bcmath.

If there were a pure PHP polyfill for bcmath or gmp, then I could use that to perform the calculations and return a string number. Then, the caller can use whatever math library they wish. This is my preferred approach, but I have yet to find a pure PHP polyfill for bcmath or gmp. phpseclib does provide a pure PHP implementation, but it is far more than I need, and I prefer that the polyfill provide the bcmath or gmp functions rather than an abstraction around them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment