Skip to content

Commit

Permalink
Fixing libraries to no go into endless recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal1996 committed Mar 5, 2024
1 parent cd2d627 commit 5f77b1d
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/libraries/System.Private.CoreLib/src/System/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,8 +1615,8 @@ private static double ULongToDouble(ulong val)
private static ulong DoubleToULong(double val)
{
#if TARGET_X86 || TARGET_AMD64
const double uint64_max_plus_1 = (double)ulong.MaxValue;
return (double.IsNaN(val) || val < 0) ? 0 : (val >= uint64_max_plus_1) ? ulong.MaxValue : (ulong)val;
const double two64 = 4294967296.0 * 4294967296.0;
return double.IsNaN(val) || (val < 0) ? 0 : (val >= two64) ? ulong.MaxValue : (ulong)(long)val;
#else
const double two63 = 2147483648.0 * 4294967296.0;
ulong ret;
Expand Down Expand Up @@ -1732,23 +1732,15 @@ private static double DoubleReminder(double dividend, double divisor)

private static int DoubleToInt(double val)
{
#if TARGET_X86 || TARGET_AMD64
const double int32_min = (double)int.MinValue - 1.0;
const double int32_max = -2.0 * (double)int.MinValue;
return (double.IsNaN(val)) ? 0 : (val <= int32_min) ? int.MinValue : (val >= int32_max) ? int.MaxValue : (int)val;
#else
(int)(long)val;
#endif // TARGET_X86 || TARGET_AMD64
const double int64_min = -2147483648.0;
const double int64_max = 2147483648.0;
return double.IsNaN(val) ? 0 : (val <= int64_min) ? int.MinValue : (val >= int64_max) ? int.MaxValue : (int)(long)val;
}

private static uint DoubleToUInt(double val)
{
#if TARGET_X86 || TARGET_AMD64
double uint_max = (double)uint.MaxValue;
return (double.IsNaN(val) || val <= 0) ? 0 : (val >= uint_max) ? uint.MaxValue : (uint)val;
#else
(uint)(long)val;
#endif // TARGET_X86 || TARGET_AMD64
const double two32 = 4294967296.0;
return double.IsNaN(val) || (val < 0) ? 0 : (val > two32) ? uint.MaxValue : (uint)(long)val;
}
}
}

0 comments on commit 5f77b1d

Please sign in to comment.