2024-01-27 22:23:54 +00:00
|
|
|
//fast inverse sqrt
|
|
|
|
function fisqrt(number) {
|
2024-01-27 19:49:39 +00:00
|
|
|
const threehalfs = 1.5;
|
|
|
|
const x2 = number * 0.5;
|
|
|
|
let i = new Float32Array(1);
|
|
|
|
i[0] = number;
|
|
|
|
let y = new Int32Array(i.buffer);
|
|
|
|
y = threehalfs - (x2 * y * y);
|
2024-01-27 20:10:42 +00:00
|
|
|
y = Math.abs(y);
|
|
|
|
y = (y / 1000000000000000000);
|
2024-01-27 22:02:02 +00:00
|
|
|
y = (y - ((Math.floor(y) / 10) / (threehalfs * number))) / 1.55;
|
2024-01-27 20:10:42 +00:00
|
|
|
y = Math.round(y * 100) / 100;
|
2024-01-27 19:49:39 +00:00
|
|
|
return y;
|
2023-11-23 20:42:46 +00:00
|
|
|
}
|
2024-01-27 22:23:54 +00:00
|
|
|
|
|
|
|
//manual sqrt
|
|
|
|
function msqrt(number) {
|
|
|
|
for (var i = 0; i * i <= number; i++) {
|
|
|
|
if (i * i === number)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
|
|
|
//square
|
|
|
|
function sq(number) {
|
|
|
|
return number * number;
|
|
|
|
}
|