-
Notifications
You must be signed in to change notification settings - Fork 205
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
Detecting overflows... #20
Comments
Your solution looks OK to me. There is no analogy between |
How to know if it overflows after it is a Long object?
|
It overflows like any other (64 bit) two's complement integer. |
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? |
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). |
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... |
I noticed that an overflow may not be as straight forward as detecting one in JavaScript (via MAX_SAFE_INTEGER). For example, the resulting value falls in range with respect to Long.MAX_VALUE or Long.MAX_UNSIGNED_VALUE
So, how would one detect an overflow?
As a work-around, what do you think of this?
The text was updated successfully, but these errors were encountered: