safe aSin

This commit is contained in:
jordan4ibanez 2024-04-19 05:09:35 -04:00
parent 40457bbdc0
commit bf0a10d62f
2 changed files with 6 additions and 0 deletions

1
minetest-api.d.ts vendored
View File

@ -1750,6 +1750,7 @@ declare global {
function truncate(floating: number): number; function truncate(floating: number): number;
function fma(x: number, y: number, z: number): number; function fma(x: number, y: number, z: number): number;
function invsqrt(r: number): number; function invsqrt(r: number): number;
function safeAsin(r: number): number;
} }
namespace string { namespace string {

View File

@ -6,6 +6,7 @@ namespace utility {
const PI2 = math.pi * 2; const PI2 = math.pi * 2;
const random = math.random; const random = math.random;
const sqrt = math.sqrt; const sqrt = math.sqrt;
const asin = math.asin;
export function randomRange(min: number, max: number): number { export function randomRange(min: number, max: number): number {
return (random() * (max - min) + min); return (random() * (max - min) + min);
@ -64,4 +65,8 @@ namespace utility {
return 1.0 / sqrt(r); return 1.0 / sqrt(r);
}; };
math.safeAsin = function (r: number): number {
return r <= -1.0 ? -PI_HALF : r >= 1.0 ? PI_HALF : asin(r);
};
} }