Bit query and bit rotation functions for Int, Long, Short, Byte

#KT-12749
This commit is contained in:
Ilya Gorbunov
2019-05-05 06:15:00 +03:00
parent 32fc131d62
commit f8724654a1
8 changed files with 836 additions and 3 deletions
@@ -230,6 +230,17 @@ if (typeof Math.log2 === "undefined") {
return Math.log(x) * Math.LOG2E;
};
}
if (typeof Math.clz32 === "undefined") {
Math.clz32 = (function(log, LN2) {
return function(x) {
var asUint = x >>> 0;
if (asUint === 0) {
return 32;
}
return 31 - (log(asUint) / LN2 | 0) | 0; // the "| 0" acts like math.floor
};
})(Math.log, Math.LN2);
}
// For HtmlUnit and PhantomJs
if (typeof ArrayBuffer.isView === "undefined") {