Git Product home page Git Product logo

Comments (6)

dcodeIO avatar dcodeIO commented on June 22, 2024

Your solution looks OK to me. There is no analogy between Number.MAX_SAFE_INTEGER and Long.js though, as this constant rather indicates precision loss for greater magnitudes due to JavaScript numbers being doubles internally.

from long.js.

jcalfee avatar jcalfee commented on June 22, 2024

How to know if it overflows after it is a Long object?

> Long.fromString("0").add(Long.MAX_VALUE).toString()
'9223372036854775807'
> Long.fromString("1").add(Long.MAX_VALUE).toString()
'-9223372036854775808'

from long.js.

dcodeIO avatar dcodeIO commented on June 22, 2024

It overflows like any other (64 bit) two's complement integer.

from long.js.

jcalfee avatar jcalfee commented on June 22, 2024

Interesting ... I'm guessing here, but I'm starting to think that overflows may be a case-by-case scenario. If so this may mean that Long.js is ideal for ByteBuffer but that I may need to go to a larger number library like bn.js for what I'm trying to do. In this way, I can overflow 64 bits getting the correct answer but checking my final result to see if it exceeds the 64 bits. I believe you mentioned bn.js. Is that not over-kill though for 64 bits? Do you think your library will be more efficient for these?

from long.js.

dcodeIO avatar dcodeIO commented on June 22, 2024

Unfortunately, I am not familiar with the bn.js codebase and don't know how efficient it is, but it might be an option if you need to work with more than exactly 64 bits of information (or a change of sign is not a good enough indicator for an overflow).

from long.js.

jcalfee avatar jcalfee commented on June 22, 2024

Ok, so "not supported" ... I think, if supported, overflow detection would need to be internal to the library and performed on all operations. I will use a large number library instead so I can work it out on my side. Thank you...

from long.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.