From 7569231a0ae3f0a7f5a6697b2ce4f09a0cf50a43 Mon Sep 17 00:00:00 2001 From: DCurrent Date: Tue, 23 Dec 2025 20:48:20 -0500 Subject: [PATCH] Fix acos and atan (previously implemented broken ordinal functions, now call respective C acos and atan). --- engine/source/openborscript/math.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/engine/source/openborscript/math.c b/engine/source/openborscript/math.c index 835ae8b88..453abb57e 100644 --- a/engine/source/openborscript/math.c +++ b/engine/source/openborscript/math.c @@ -129,8 +129,12 @@ HRESULT math_acos(ScriptVariant **varlist , ScriptVariant **pretvar, int paramCo { double PI = 3.14159265; + // Clamp for safety: acos domain is [-1, 1] + if (dbltemp > 1.0) { dbltemp = 1.0; } + if (dbltemp < -1.0) { dbltemp = -1.0; } + ScriptVariant_ChangeType(*pretvar, VT_DECIMAL); - (*pretvar)->dblVal = (DOUBLE)(aacos((double)dbltemp) * 180.0 / PI); + (*pretvar)->dblVal = (DOUBLE)(acos((double)dbltemp) * 180.0 / PI); return S_OK; } *pretvar = NULL; @@ -146,7 +150,7 @@ HRESULT math_atan(ScriptVariant **varlist , ScriptVariant **pretvar, int paramCo double PI = 3.14159265; ScriptVariant_ChangeType(*pretvar, VT_DECIMAL); - (*pretvar)->dblVal = (DOUBLE)(aatan((double)dbltemp) * 180.0 / PI); + (*pretvar)->dblVal = (DOUBLE)(atan((double)dbltemp) * 180.0 / PI); return S_OK; } *pretvar = NULL;