From 329834538e262318f5cf599d9e98a748b9f6a8b9 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 27 May 2022 08:59:18 -0700 Subject: [PATCH] Ensure `JIT_Dbl2ULng` correctly handles NaN --- src/coreclr/vm/jithelpers.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 2c2d3b9a3048e..49d07f1206e92 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -595,10 +595,14 @@ HCIMPL1_V(UINT64, JIT_Dbl2ULng, double val) if (val < two63) { ret = FastDbl2Lng(val); } - else { + else if (!_isnan(val)) { // subtract 0x8000000000000000, do the convert then add it back again ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000); } + else { + // specially handle NaN otherwise we return (Int64.MaxValue + 1) + ret = 0; + } return ret; } HCIMPLEND