From: Hyeongseok Oh Date: Tue, 23 Aug 2016 08:07:47 +0000 (+0900) Subject: fix for infinite and NaN double X-Git-Tag: submit/tizen/20210909.063632~11030^2~9461^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b077b6439be498be9312e3e996da8c68185d2864;p=platform%2Fupstream%2Fdotnet%2Fruntime.git fix for infinite and NaN double Commit migrated from https://github.com/dotnet/coreclr/commit/3ed59739b770dbafb494d06ea5a0a314974542b3 --- diff --git a/src/coreclr/src/vm/jithelpers.cpp b/src/coreclr/src/vm/jithelpers.cpp index 0f05342..d362078 100644 --- a/src/coreclr/src/vm/jithelpers.cpp +++ b/src/coreclr/src/vm/jithelpers.cpp @@ -613,21 +613,36 @@ HCIMPL1_V(UINT64, JIT_Dbl2ULng, double val) const double two63 = 2147483648.0 * 4294967296.0; UINT64 ret; - if (val < two63) { #ifdef _TARGET_XARCH_ + if (val < two63) { ret = FastDbl2Lng(val); + } + else { + // subtract 0x8000000000000000, do the convert then add it back again + ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000); + } #else // In x86/x64, conversion result of negative double to unsigned integer is // bit-equivalent unsigned value. // But other architecture's compiler convert negative doubles to zero when // the target is unsigned. + if (!_finite(val)) { ret = UINT64(val); -#endif } - else { - // subtract 0x8000000000000000, do the convert then add it back again - ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000); -} + else { + if (val >= 0.0) { + if (val < two63) { + ret = UINT64(val); + } + else { + ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000); + } + } + else { + ret = UINT64(val); + } + } +#endif return ret; } HCIMPLEND