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

Commit c060890

Browse files
committed
[Bug 14678] com.livecode.math: Generate domain errors from log10() and ln()
1 parent 4ec2b88 commit c060890

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

libscript/src/module-math.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ extern "C" MC_DLLEXPORT void MCMathEvalNumberToPowerOfNumber(MCNumberRef p_left,
5858

5959
extern "C" MC_DLLEXPORT void MCMathEvalBase10LogReal(double p_operand, double& r_output)
6060
{
61+
errno = 0;
6162
r_output = log10(p_operand);
63+
64+
if (errno == EDOM)
65+
{
66+
MCErrorCreateAndThrow (kMCMathDomainErrorTypeInfo, nil);
67+
}
6268
}
6369

6470
extern "C" MC_DLLEXPORT void MCMathEvalBase10LogNumber(MCNumberRef p_operand, MCNumberRef& r_output)
@@ -75,7 +81,13 @@ extern "C" MC_DLLEXPORT void MCMathEvalBase10LogNumber(MCNumberRef p_operand, MC
7581

7682
extern "C" MC_DLLEXPORT void MCMathEvalNaturalLogReal(double p_operand, double& r_output)
7783
{
84+
errno = 0;
7885
r_output = log(p_operand);
86+
87+
if (errno == EDOM)
88+
{
89+
MCErrorCreateAndThrow (kMCMathDomainErrorTypeInfo, nil);
90+
}
7991
}
8092

8193
extern "C" MC_DLLEXPORT void MCMathEvalNaturalLogNumber(MCNumberRef p_operand, MCNumberRef& r_output)

tests/lcb/stdlib/math.lcb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ handler TestLog10Domain_Zero() as undefined
8383
put the log of 0 into tVar
8484
end handler
8585
public handler TestLog10Domain()
86-
MCUnitTestHandlerThrowsBroken(TestLog10Domain_Negative, "log10 (syntax, -ve)", "bug 14678")
86+
-- bug 14678
87+
MCUnitTestHandlerThrows(TestLog10Domain_Negative, "log10 (syntax, -ve)")
88+
8789
MCUnitTestHandlerThrowsBroken(TestLog10Domain_Zero, "log10 (syntax, 0)", "bug 14678")
8890
end handler
8991

@@ -159,7 +161,8 @@ handler TestLnDomain_Zero() as undefined
159161
put the natural log of 0 into tVar
160162
end handler
161163
public handler TestLnDomain()
162-
MCUnitTestHandlerThrowsBroken(TestLnDomain_Negative, "ln (syntax, -ve)", "bug 14678")
164+
-- bug 14678
165+
MCUnitTestHandlerThrows(TestLnDomain_Negative, "ln (syntax, -ve)")
163166
MCUnitTestHandlerThrowsBroken(TestLnDomain_Zero, "ln (syntax, 0)", "bug 14678")
164167
end handler
165168

0 commit comments

Comments
 (0)