Skip to content

Commit 5f77b1d

Browse files
committed
Fixing libraries to no go into endless recursion
1 parent cd2d627 commit 5f77b1d

File tree

1 file changed

+7
-15
lines changed
  • src/libraries/System.Private.CoreLib/src/System

1 file changed

+7
-15
lines changed

src/libraries/System.Private.CoreLib/src/System/Math.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,8 @@ private static double ULongToDouble(ulong val)
16151615
private static ulong DoubleToULong(double val)
16161616
{
16171617
#if TARGET_X86 || TARGET_AMD64
1618-
const double uint64_max_plus_1 = (double)ulong.MaxValue;
1619-
return (double.IsNaN(val) || val < 0) ? 0 : (val >= uint64_max_plus_1) ? ulong.MaxValue : (ulong)val;
1618+
const double two64 = 4294967296.0 * 4294967296.0;
1619+
return double.IsNaN(val) || (val < 0) ? 0 : (val >= two64) ? ulong.MaxValue : (ulong)(long)val;
16201620
#else
16211621
const double two63 = 2147483648.0 * 4294967296.0;
16221622
ulong ret;
@@ -1732,23 +1732,15 @@ private static double DoubleReminder(double dividend, double divisor)
17321732

17331733
private static int DoubleToInt(double val)
17341734
{
1735-
#if TARGET_X86 || TARGET_AMD64
1736-
const double int32_min = (double)int.MinValue - 1.0;
1737-
const double int32_max = -2.0 * (double)int.MinValue;
1738-
return (double.IsNaN(val)) ? 0 : (val <= int32_min) ? int.MinValue : (val >= int32_max) ? int.MaxValue : (int)val;
1739-
#else
1740-
(int)(long)val;
1741-
#endif // TARGET_X86 || TARGET_AMD64
1735+
const double int64_min = -2147483648.0;
1736+
const double int64_max = 2147483648.0;
1737+
return double.IsNaN(val) ? 0 : (val <= int64_min) ? int.MinValue : (val >= int64_max) ? int.MaxValue : (int)(long)val;
17421738
}
17431739

17441740
private static uint DoubleToUInt(double val)
17451741
{
1746-
#if TARGET_X86 || TARGET_AMD64
1747-
double uint_max = (double)uint.MaxValue;
1748-
return (double.IsNaN(val) || val <= 0) ? 0 : (val >= uint_max) ? uint.MaxValue : (uint)val;
1749-
#else
1750-
(uint)(long)val;
1751-
#endif // TARGET_X86 || TARGET_AMD64
1742+
const double two32 = 4294967296.0;
1743+
return double.IsNaN(val) || (val < 0) ? 0 : (val > two32) ? uint.MaxValue : (uint)(long)val;
17521744
}
17531745
}
17541746
}

0 commit comments

Comments
 (0)