0

I have a var blah = ctypes.UInt64('65'), the 65 is really anything. I need to do math on that, but when I do:

console.log(blah * ctypes.UInt64('2') it removes the ctypes.UInt64 wrap. I need to keep that wrap so I can pass it into something else, I know I can re-wrap it, but whats the proper way to do math on UInt64 and Int64 please.

nmaier
  • 32,336
  • 5
  • 63
  • 78
Noitidart
  • 35,443
  • 37
  • 154
  • 323

1 Answers1

1

There is no API/library to do math on js-ctypes Int64 types.

You'll need to unwrap and re-wrap as needed and of course do enough error checking and handling to know when it is safe to unwrap stuff and what math operations might lose precision (>53bit) and/or overflow numbers.

If you cannot use regular JS double precision float math, because you really need those 64-bit, then you'll need read up on bignum math and how to do it with small-numbers, or find a suitable bignum library. However, the numbers from your example do not require this.

And avoid doing int64 math in the first place, if possible; but of course, that is not always possible.

Community
  • 1
  • 1
nmaier
  • 32,336
  • 5
  • 63
  • 78
  • Aw drats ok re-wrapping it is. Yep I'll definitely use that post you gave me earlier to check bits before i do the math. – Noitidart Jun 23 '14 at 10:28