Comments (11)
@Yaffle care to add example code?
from bn.js.
var a = "-178";
var n = "10";
var q = new BN(a, 10).div(new BN(n, 10)).toString();
var r = new BN(a, 10).mod(new BN(n, 10)).toString();
console.log("${a} = ${n} * ${q} + ${r}".replace("${a}", a).replace("${n}", n).replace("${q}", q).replace("${r}", r));
from bn.js.
Should be fixed by #54 . PTAL.
@dcousens I need to consult with you on this a bit. It is a breaking change, and I wonder if there might be any modules that will need to be updated to support this one. The main difference is that .mod()
will now return negative number, when the input was negative itself.
There was few places in elliptic
that needs to be fixed, but it wasn't that complicated (considering that I have pretty big test case).
What are your thoughts? Is it worth fixing, at the price of potentially breaking user code in un-obvious places?
from bn.js.
This could break a lot of existing code, especially since its an assumptions many users could be relying on.
In my case, I know for a fact I am relying on this relying on this behaviour, however, those cases are relying on a different BN library.
At best, this change is absolutely a major version bump IMHO.
@calvinmetcalf thoughts?
edit: Seems the only place this might affect crypto-browserify
is in https://github.com/indutny/miller-rabin/blob/master/lib/mr.js, though it gets put in a red first, @indutny thoughts?
from bn.js.
@dcousens I have a pending fix for elliptic library, but this will require major bump on it as well. I guess we can deal with it.
Still would like to hear @calvinmetcalf thoughts on this.
from bn.js.
Doesn't it make sense to make the fix for the sake of correctness and predicability and to just bump the major? Maintaining a changelog would help to communicate these sorts of issues for anyone that wants to upgrade major versions.
from bn.js.
@jprichardson the problem is that checking it might be not trivial. But I agree that it should be done.
from bn.js.
Possibly, you might change umod
too.
a | n | mod(master) | umod(fix/gh-47) | Euclidean division |
---|---|---|---|---|
4 | 3 | 1 | 1 | 1 |
4 | -3 | 1 | 1 | 1 |
-4 | 3 | 2 | 2 | 2 |
-4 | -3 | 1 | -4 | 2 |
from bn.js.
Ok, I think it should throw on negative reduction number in umod
. Does it sound right?
from bn.js.
I think, you might change umod
to "euclidean division" if you so like non-negative results...
from bn.js.
@Yaffle thanks, fixed.
from bn.js.
Related Issues (20)
- Easiest way to get percentage HOT 10
- muln with fractional number gives wrong result HOT 3
- Add method for "not equal"
- Assertion failure error message could be helpful
- Use bn.js instead of bignumber.js
- Incorrect multiplication result when using muln() HOT 1
- Converting json.stringified BN back into BN HOT 2
- use in web HOT 1
- TypeError: bn_js_1.default is not a constructor
- Add support for raising a `BN` object to the power of a plain JavaScript Number
- Function `mod` gives incorrect results when the arguments are of opposite signs
- setn function signature in index.tx doesn't correspond with the library HOT 1
- Which rounding method is used?
- Base64 encoding
- Wrong `cmpn` result HOT 1
- The unit of length in `toBuffer(endian, length)` is unclear
- Property 'divmod' does not exist on type 'BN'
- Add link to library this is based on to docs
- BN.muln with number bigger than 0x4000000 HOT 1
- I'm gonna find every one of you
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 bn.js.