Skip to content

Commit 7569231

Browse files
committed
Fix acos and atan (previously implemented broken ordinal functions, now call respective C acos and atan).
1 parent 7a293b7 commit 7569231

File tree

1 file changed

+6
-2
lines changed
  • engine/source/openborscript

1 file changed

+6
-2
lines changed

engine/source/openborscript/math.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ HRESULT math_acos(ScriptVariant **varlist , ScriptVariant **pretvar, int paramCo
129129
{
130130
double PI = 3.14159265;
131131

132+
// Clamp for safety: acos domain is [-1, 1]
133+
if (dbltemp > 1.0) { dbltemp = 1.0; }
134+
if (dbltemp < -1.0) { dbltemp = -1.0; }
135+
132136
ScriptVariant_ChangeType(*pretvar, VT_DECIMAL);
133-
(*pretvar)->dblVal = (DOUBLE)(aacos((double)dbltemp) * 180.0 / PI);
137+
(*pretvar)->dblVal = (DOUBLE)(acos((double)dbltemp) * 180.0 / PI);
134138
return S_OK;
135139
}
136140
*pretvar = NULL;
@@ -146,7 +150,7 @@ HRESULT math_atan(ScriptVariant **varlist , ScriptVariant **pretvar, int paramCo
146150
double PI = 3.14159265;
147151

148152
ScriptVariant_ChangeType(*pretvar, VT_DECIMAL);
149-
(*pretvar)->dblVal = (DOUBLE)(aatan((double)dbltemp) * 180.0 / PI);
153+
(*pretvar)->dblVal = (DOUBLE)(atan((double)dbltemp) * 180.0 / PI);
150154
return S_OK;
151155
}
152156
*pretvar = NULL;

0 commit comments

Comments
 (0)