diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2016-04-15 08:07:20 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-04-15 08:07:20 +0300 |
commit | 08a5d11f5648e0cddd840bbd1460f5ea63901de4 (patch) | |
tree | 26d554e80d0a2ecd2c476227c72576f8caee5334 /src/Native/Runtime/MathHelpers.cpp | |
parent | cf2f155def982ef7a6da663c3bf91c4faf72e08a (diff) |
Implement FltRem and DblRem JIT helpers (#1128)
Diffstat (limited to 'src/Native/Runtime/MathHelpers.cpp')
-rw-r--r-- | src/Native/Runtime/MathHelpers.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Native/Runtime/MathHelpers.cpp b/src/Native/Runtime/MathHelpers.cpp index cc4b51a43..d720a6368 100644 --- a/src/Native/Runtime/MathHelpers.cpp +++ b/src/Native/Runtime/MathHelpers.cpp @@ -82,6 +82,60 @@ EXTERN_C REDHAWK_API UInt64 REDHAWK_CALLCONV RhpDbl2ULng(double val) return((UInt64)val); } +// CORERT Specific - on Project N the arguments to these helpers are inverted +#ifdef CORERT +#include <cmath> + +EXTERN_C REDHAWK_API float REDHAWK_CALLCONV RhpFltRem(float dividend, float divisor) +{ + // + // From the ECMA standard: + // + // If [divisor] is zero or [dividend] is infinity + // the result is NaN. + // If [divisor] is infinity, + // the result is [dividend] (negated for -infinity***). + // + // ***"negated for -infinity" has been removed from the spec + // + + if (divisor==0 || !std::isfinite(dividend)) + { + return -nanf(0); + } + else if (!std::isfinite(divisor) && !std::isnan(divisor)) + { + return dividend; + } + // else... + return fmodf(dividend,divisor); +} + +EXTERN_C REDHAWK_API double REDHAWK_CALLCONV RhpDblRem(double dividend, double divisor) +{ + // + // From the ECMA standard: + // + // If [divisor] is zero or [dividend] is infinity + // the result is NaN. + // If [divisor] is infinity, + // the result is [dividend] (negated for -infinity***). + // + // ***"negated for -infinity" has been removed from the spec + // + if (divisor==0 || !std::isfinite(dividend)) + { + return -nan(0); + } + else if (!std::isfinite(divisor) && !std::isnan(divisor)) + { + return dividend; + } + // else... + return(fmod(dividend,divisor)); +} +#endif // CORERT + #ifdef _ARM_ EXTERN_C REDHAWK_API Int32 REDHAWK_CALLCONV RhpIDiv(Int32 i, Int32 j) { |