failed-fastInverseSqrtJS/index.js

25 lines
526 B
JavaScript
Raw Normal View History

2024-01-27 16:23:54 -06:00
//fast inverse sqrt
function fisqrt(number) {
2024-01-27 13:49:39 -06: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 14:10:42 -06:00
y = Math.abs(y);
y = (y / 1000000000000000000);
2024-01-27 16:02:02 -06:00
y = (y - ((Math.floor(y) / 10) / (threehalfs * number))) / 1.55;
2024-01-27 14:10:42 -06:00
y = Math.round(y * 100) / 100;
2024-01-27 13:49:39 -06:00
return y;
2023-11-23 14:42:46 -06:00
}
2024-01-27 16:23:54 -06:00
2024-01-27 16:28:02 -06:00
//square
function sq(n1, n2) {
return n1 * n2;
2024-01-27 16:23:54 -06:00
}
2024-01-27 16:28:02 -06:00
//square self
function sqs(number) {
2024-01-27 16:23:54 -06:00
return number * number;
}