Comments (6)
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.
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.
It overflows like any other (64 bit) two's complement integer.
from long.js.
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.
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.
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)
- Migrate to ESM HOT 1
- Using symbol for isLong HOT 2
- Add default value of unsigned in Long.fromInt to docs
- How to return a uint64? HOT 4
- isPositive returns true for zero
- Is the heigh argument in Long constructor required? HOT 2
- Switch to ESM breaks 3rd party libraries HOT 8
- [BUG] this.isZero is not function
- WASM check causes Node 16.1+ crash on ARMv6 HOT 3
- Unable import in TypeScript since v5+ HOT 8
- Add copyright line to licence
- protobuf fromNumber encoding error HOT 2
- Cannot import package using ES modules HOT 1
- Please available on module commonjs
- fromString with a string that isn't an integer behaves weird
- TypeScript errors with moduleResolution nodenext HOT 16
- "./package.json" is not defined by "exports" warning in React Native HOT 2
- For packaging for debian => need source information HOT 6
- Issue when running build on a NodeJS app HOT 4
- Patch
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 long.js.