|
19 | 19 | #include <foundation-system.h> |
20 | 20 |
|
21 | 21 | #include <float.h> |
| 22 | +#include <errno.h> |
22 | 23 |
|
23 | 24 | // Older versions of MSVC don't supply "trunc" |
24 | 25 | #ifdef _WIN32 |
25 | 26 | double trunc(double f) { return f < 0 ? ceil(f) : floor(f); } |
26 | 27 | #endif |
27 | 28 |
|
| 29 | +//////////////////////////////////////////////////////////////// |
| 30 | + |
| 31 | +MCTypeInfoRef kMCMathDomainErrorTypeInfo; |
| 32 | + |
| 33 | +//////////////////////////////////////////////////////////////// |
| 34 | + |
28 | 35 | extern "C" MC_DLLEXPORT void MCMathEvalRealToPowerOfReal(double p_left, double p_right, double& r_output) |
29 | 36 | { |
30 | | - if (p_right == 0) |
31 | | - { |
32 | | - r_output = 1.0; |
33 | | - return; |
34 | | - } |
35 | | - |
| 37 | + errno = 0; |
36 | 38 | r_output = pow(p_left, p_right); |
| 39 | + |
| 40 | + if (errno == EDOM) |
| 41 | + { |
| 42 | + MCErrorCreateAndThrow (kMCMathDomainErrorTypeInfo, nil); |
| 43 | + } |
37 | 44 | } |
38 | 45 |
|
39 | 46 | extern "C" MC_DLLEXPORT void MCMathEvalNumberToPowerOfNumber(MCNumberRef p_left, MCNumberRef p_right, MCNumberRef& r_output) |
@@ -413,4 +420,21 @@ extern "C" MC_DLLEXPORT void MCMathEvalConvertBase(MCStringRef p_operand, intege |
413 | 420 | MCErrorCreateAndThrow(kMCGenericErrorTypeInfo, "reason", MCSTR("integer overflow, or invalid character in source"), nil); |
414 | 421 | } |
415 | 422 |
|
| 423 | +//////////////////////////////////////////////////////////////// |
| 424 | + |
| 425 | +bool |
| 426 | +MCMathModuleInitialize (void) |
| 427 | +{ |
| 428 | + if (!MCNamedErrorTypeInfoCreate (MCNAME("com.livecode.math.DomainError"), MCNAME("math"), MCSTR("mathematical function domain error"), kMCMathDomainErrorTypeInfo)) |
| 429 | + return false; |
| 430 | + |
| 431 | + return true; |
| 432 | +} |
| 433 | + |
| 434 | +void |
| 435 | +MCMathModuleFinalize (void) |
| 436 | +{ |
| 437 | + MCValueRelease (kMCMathDomainErrorTypeInfo); |
| 438 | +} |
| 439 | + |
416 | 440 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
0 commit comments