Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 04d9c23

Browse files
committed
[Bug 14681] com.livecode.math: Generate domain errors for arcsin and arcos
1 parent c060890 commit 04d9c23

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

libscript/src/module-math.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ extern "C" MC_DLLEXPORT void MCMathEvalTanNumber(MCNumberRef p_operand, MCNumber
172172

173173
extern "C" MC_DLLEXPORT void MCMathEvalAsinReal(double p_operand, double& r_output)
174174
{
175+
errno = 0;
175176
r_output = asin(p_operand);
177+
178+
if (errno == EDOM)
179+
{
180+
MCErrorCreateAndThrow (kMCMathDomainErrorTypeInfo, nil);
181+
}
176182
}
177183

178184
extern "C" MC_DLLEXPORT void MCMathEvalAsinNumber(MCNumberRef p_operand, MCNumberRef& r_output)
@@ -189,7 +195,13 @@ extern "C" MC_DLLEXPORT void MCMathEvalAsinNumber(MCNumberRef p_operand, MCNumbe
189195

190196
extern "C" MC_DLLEXPORT void MCMathEvalAcosReal(double p_operand, double& r_output)
191197
{
198+
errno = 0;
192199
r_output = acos(p_operand);
200+
201+
if (errno == EDOM)
202+
{
203+
MCErrorCreateAndThrow (kMCMathDomainErrorTypeInfo, nil);
204+
}
193205
}
194206

195207
extern "C" MC_DLLEXPORT void MCMathEvalAcosNumber(MCNumberRef p_operand, MCNumberRef& r_output)

tests/lcb/stdlib/math.lcb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,15 @@ public handler TestArctan()
121121
test "arctan2 (function)" when the binary arctangent of -1 and -1 is -3 * pi / 4
122122
end handler
123123

124-
handler TestTrigonometricDomain_Arcsin() as undefined
125-
variable t
126-
put asin((1 + any number) / any number) into t
124+
handler TestTrigonometricDomain_Arcsin()
125+
return asin((1 + any number) / any number)
127126
end handler
128127
handler TestTrigonometricDomain_Arccos() as undefined
129-
variable t
130-
put acos((1 + any number) / any number) into t
128+
return acos((1 + any number) / any number)
131129
end handler
132130
public handler TestTrigonometricDomain()
133-
MCUnitTestHandlerThrowsBroken(TestTrigonometricDomain_Arcsin, "arcsin (> 1)", "bug 14681")
134-
MCUnitTestHandlerThrowsBroken(TestTrigonometricDomain_Arccos, "arccos (> 1)", "bug 14681")
131+
MCUnitTestHandlerThrows(TestTrigonometricDomain_Arcsin, "arcsin (> 1)")
132+
MCUnitTestHandlerThrows(TestTrigonometricDomain_Arccos, "arccos (> 1)")
135133
end handler
136134

137135
public handler TestExp()

0 commit comments

Comments
 (0)