Comments (8)
Hi, thank you for the feature request and for providing working code! 👍
I'll take some time in the coming days to implement it in the library and add some tests.
Question: is there any value in providing gcdExtended()
as a public method? Or is it just an implementation detail, with no real value on its own? I can see that Java's BigInteger has a modInverse()
method, but no gcdExtended()
.
Finally, out of curiosity, I'd be interested to know what's your use case for modInverse()
!
from math.
With no feedback received, I've moved forward with throwing a NegativeNumberException
when the modulus is negative.
Now available as modInverse()
and released as 0.8.16! ✨
from math.
Hi,
I am happy to read that!
The method gcdExtended
can be private. At the moment, I don't see any reason for using it directly.
In my context, this function is used for the computation of the Chinese Remainder Theorem (CRT) and especially for RSA encryption algorithm (the CRT reduces the computation time).
from math.
Hi, I just started implementing modInverse()
, however it looks like the algorithm above fails for negative numbers:
gmp_invert('1234567890', '-19'); // 11
modInverse('1234567890', '-19'); // -8
gmp_invert('-1234567890', '19'); // 8
modInverse('-1234567890', '19'); // exception
gmp_invert('-1234567890', '-19'); // 8
modInverse('-1234567890', '-19'); // exception
Any idea how to fix it?
from math.
Any idea how to fix it?
No worries, I got the right result by borrowing this solution from the JDK.
from math.
Now the question is, what should we do when $m
is negative? Java & Dart throw an exception, while gmp_invert()
returns the value of modInverse($x, abs($m)). For now I've allowed negative modulo this way, but I'm not sure this is the right way the API should respond.
from math.
Otherwise looks good to me now. Could you please test the master
branch (with and without GMP please!) and report any issue?
from math.
Thank you! Sorry for the lack of feedback, but it works great.
Regards
from math.
Related Issues (20)
- brick/math method for gmp_random_range HOT 4
- The given value ".1200" does not represent a valid number. HOT 2
- Add a changelog HOT 3
- Rounding error on exactlyDividedBy() HOT 2
- Fatal error: Maximum execution time of 30 seconds exceeded HOT 2
- RFC: add `getPrecision` method. HOT 11
- Issue with dividedBy and MultipliedBy? HOT 3
- Feature Request: Implement lisachenko/z-engine HOT 1
- BigComplex HOT 2
- How to accept any scale without rounding HOT 1
- Accept hexadecimal input HOT 1
- Rounding is necessary to represent the result of the operation at this scale. HOT 2
- [0.10.0] behavior change HOT 1
- Please support php8.1 HOT 1
- Implements the Serializable interface, which is deprecated HOT 1
- `gmp_export` equivalent HOT 6
- Rounding bug, or am I just dumb? HOT 4
- Output a BigRational in decimal form with period
- Implement `__debugInfo` magic method HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from math.