// Check if number is an integer export const isInt = (value: number): boolean => { if (typeof value === "boolean") return true; return isFinite(value) ? value === Math.round(value) : false; }; // Calculate the sign of a number export const sign = Math.sign || function (x: number): number { if (x > 0) { return 1; } else if (x < 0) { return -1; } else { return 0; } }; // Calculate the base-2 logarithm of a number export const log2 = Math.log2 || function log2(x: number) { return Math.log(x) / Math.LN2; }; // Calculate the base-10 logarithm of a number export const log10 = Math.log10 || function log10(x: number) { return Math.log(x) / Math.LN10; }; // Calculate cubic root for a number export const cbrt = Math.cbrt || function cbrt(x: number) { if (x === 0) return x; const negate = x < 0; let result; if (negate) { x = -x; } if (isFinite(x)) { result = Math.exp(Math.log(x) / 3); result = (x / (result * result) + 2 * result) / 3; } else { result = x; } return negate ? -result : result; }; export const clamp = (n: number, min: number, max: number): number => { return Math.min(Math.max(n, min), max); }; export const sqrt = (n: number): number => { let x = 1.0; let z = 1.0; for (let i = 0; i < 10; i++) { z = x - (x * x - n) / (2 * x); if (z == x) { return z; } x = z; } return x; };