1

I've encountered the problem in this question: JavaScript: Bitwise shift of long long number

and converted all my relevant places in code from shifts to Math.pow(2,x) operations. Now I'm encountered a serious performance problem.

Is there a "gold way" to go? I mean a safe shift operations (until 50 bits is enough for my purpose) which are also performing well?

Community
  • 1
  • 1
MaMazav
  • 1,773
  • 3
  • 19
  • 33
  • 1
    Using only the right 50 bits would probably be an acceptable solution, no ? Using a little more numbers shouldn't be costly. In any case Math.pow looks like a very very bad one – Denys Séguret Jan 18 '16 at 09:46
  • But how do I use those 50 bits? I thought about using two variables, but I wonder if there is a better solution or a library which does it for me – MaMazav Jan 18 '16 at 09:52

1 Answers1

0

Answering my own question.

https://www.npmjs.com/package/long

This library is exactly what I need - it implements a 64 bit long. (It does not support "Big integer" - an infinite bit length integer, but if you need an efficient code for long integer it seems to be OK).

MaMazav
  • 1,773
  • 3
  • 19
  • 33