Giter Site home page Giter Site logo

Comments (11)

dcousens avatar dcousens commented on July 27, 2024

@Yaffle care to add example code?

from bn.js.

Yaffle avatar Yaffle commented on July 27, 2024

@dcousens ,

      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.

indutny avatar indutny commented on July 27, 2024

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.

dcousens avatar dcousens commented on July 27, 2024

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.

indutny avatar indutny commented on July 27, 2024

@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.

jprichardson avatar jprichardson commented on July 27, 2024

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.

indutny avatar indutny commented on July 27, 2024

@jprichardson the problem is that checking it might be not trivial. But I agree that it should be done.

from bn.js.

Yaffle avatar Yaffle commented on July 27, 2024

Possibly, you might change umod too.

a n mod(master) umod(fix/gh-47) Euclidean division
43111
4-3111
-43222
-4-31-42

from bn.js.

indutny avatar indutny commented on July 27, 2024

Ok, I think it should throw on negative reduction number in umod. Does it sound right?

from bn.js.

Yaffle avatar Yaffle commented on July 27, 2024

I think, you might change umod to "euclidean division" if you so like non-negative results...

from bn.js.

indutny avatar indutny commented on July 27, 2024

@Yaffle thanks, fixed.

from bn.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.