-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Added modMultiplicativeInverseNumber to the number arithmetic module #1749
Conversation
Thanks @ohpyupi , this is a nice start! Next step will indeed be to make an implementation that supports data types like What would make most sense to return when there is no result? Currently you return |
@josdejong Totally agree. I will start implementing supporting other types and replace |
Hi @ohpyupi, did you find some time already to work further on this PR? |
@josdejong Hi. I was busy for last few weeks. I will have time to work on it from next weekend. |
Thanks for the update! Take it easy :) |
4979636
to
a38acf8
Compare
if (b === 0) { | ||
throw new Error('divisor must be an integer') | ||
} | ||
const [div, m] = xgcdNumber(a, b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josdejong I think I cannot extend the argument type to both float and big number since xgcdNumber
throws an error if the params are non-integer. I need to update this function's logic in a way it can handle non-integer as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ohpyupi The xgcd
function indeed only works with integers.
To get a working solution for BigNumber
, you can inject xgcd
instead of using xgcdNumber
, this works for number and BigNumber. Like:
const dependencies = ['typed', 'xgcd']
// ...
export const createModMultiplicativeInverse = /* #__PURE__ */ factory(name, dependencies, ({ typed, xgcd }) => {
// ...
const [div, m] = xgcd(a, b)
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josdejong Oh cool! But what about the float type? Does it work with the float type as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function xgcd
does not support floats, only integer values. Function mod
does support floats. If needed for modMultiplicativeInverseNumber
I guess we have to extend xgcd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this? In this scope of PR, I ignore the float support for the modular inverse. And if the float support is requested, it can be implemented then. let me know if this approach works on your end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that sounds like a pragmatic approach 👍
Was this superseded by #2368 and should be closed? |
I think so. Let's close this PR. Feel free to reopen if needed Hoseong Lee. |
Addressed #1744
So far, I added a function
modMultiplicativeInverseNumber
in the number arithmetic module. And I guess remaining task is to implement this function to the library. But before doing it, I wanted to open this PR to get feedbacks and comments in early steps.