0

I have a question. I'm trying to sum up ints in node, but this happens in the repl:

144115291155089440
> 32 + 2048 + 16384 + 34359738368 + 68719476736 + 144115188075855870 + 4
144115291155089440
> 32 + 2048 + 16384 + 34359738368 + 68719476736 + 144115188075855870
144115291155089440

Can someone explain why this is happening? Context is I'm referring to this API (https://moz.com/help/guides/moz-api/mozscape/api-reference/url-metrics) and trying to use return a Cols value for their BitFlag.

Thanks again!

5
  • have you checked what your max int is? It sound like you are exceeding the max int value and need to use another data type. This is a good reason to learn c or c++ programming because you learn that you have to check that operations don't exceed max int values. Commented Feb 19, 2018 at 21:59
  • Number.MAX_SAFE_INTEGER => 9007199254740991 Commented Feb 19, 2018 at 22:01
  • 1
    See also max integer value in JavaScript Commented Feb 19, 2018 at 22:01
  • @MatthewLagerwey unfortunately you must write a software implementation in JavaScript to handle integers over 2**53-1, since there are no native data types for Uint64 or Int64. Commented Feb 19, 2018 at 22:08
  • Here's one I wrote a while back. It handles up to 2**64-1, but I haven't written a toString() method for it since I didn't need one. I'll leave that up to you. Commented Feb 19, 2018 at 22:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.