lemire / FastBitSet.js

Speed-optimized BitSet implementation for modern browsers and JavaScript engines
Apache License 2.0
158 stars 19 forks source link

question: 0 | 0 #21

Closed missinglink closed 1 year ago

missinglink commented 1 year ago

Hi Daniel,

Apologies for opening an issue for this as it's more of a question for which I wasn't able to find an answer online. In this code you use an unusual convention of initialising variables with 0 | 0, example

What is the purpose of this? I'm assuming it has a performance benefit but I can't imagine what since it seems unintuitive to me.

Please feel free to close this issue 🙏

Kind Regards Peter

lemire commented 1 year ago

By default, numbers in javascript are binary64 numbers (floating-point numbers). We want to the the JavaScript compiler that our numbers are integers. The operator | returns returns a 32-bit integer, by definition.

missinglink commented 1 year ago

Thanks for your response, makes sense but I wasn't aware that internally JS engines had multiple different numeric types as they are not exposed to the user.

Are you able to recommend some reading material which covers this topic where I can learn more without digging through the source code of V8 or whatever?

lemire commented 1 year ago

It would be best to raise the issue with the v8 community if v8 is your target. Generally speaking, the documentation of the behaviour of the JavaScript engine should be under the responsibility of the engine itself.