Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,16 +1420,24 @@ private static bool TryConvertTo<TOther>(double value, [MaybeNullWhen(false)] ou
}
else if (typeof(TOther) == typeof(uint))
{
#if MONO
uint actualResult = (value >= uint.MaxValue) ? uint.MaxValue :
(value <= uint.MinValue) ? uint.MinValue : (uint)value;
#else
uint actualResult = (uint)value;
#endif
result = (TOther)(object)actualResult;
return true;
}
else if (typeof(TOther) == typeof(ulong))
{
#if MONO
ulong actualResult = (value >= ulong.MaxValue) ? ulong.MaxValue :
(value <= ulong.MinValue) ? ulong.MinValue :
IsNaN(value) ? 0 : (ulong)value;
#else
ulong actualResult = (ulong)value;
#endif
result = (TOther)(object)actualResult;
return true;
}
Expand All @@ -1442,17 +1450,19 @@ private static bool TryConvertTo<TOther>(double value, [MaybeNullWhen(false)] ou
}
else if (typeof(TOther) == typeof(nuint))
{
#if MONO
#if TARGET_64BIT
nuint actualResult = (value >= ulong.MaxValue) ? unchecked((nuint)ulong.MaxValue) :
(value <= ulong.MinValue) ? unchecked((nuint)ulong.MinValue) : (nuint)value;
result = (TOther)(object)actualResult;
return true;
#else
nuint actualResult = (value >= uint.MaxValue) ? uint.MaxValue :
(value <= uint.MinValue) ? uint.MinValue : (nuint)value;
#endif
#else
nuint actualResult = (nuint)value;
#endif
result = (TOther)(object)actualResult;
return true;
#endif
}
else
{
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Int32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,12 @@ private static bool TryConvertFromSaturating<TOther>(TOther value, out int resul
if (typeof(TOther) == typeof(double))
{
double actualValue = (double)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (int)actualValue;
#else
result = (int)actualValue;
#endif
return true;
}
else if (typeof(TOther) == typeof(Half))
Expand Down Expand Up @@ -1049,8 +1053,12 @@ private static bool TryConvertFromSaturating<TOther>(TOther value, out int resul
else if (typeof(TOther) == typeof(float))
{
float actualValue = (float)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (int)actualValue;
#else
result = (int)actualValue;
#endif
return true;
}
else
Expand Down Expand Up @@ -1080,8 +1088,12 @@ private static bool TryConvertFromTruncating<TOther>(TOther value, out int resul
if (typeof(TOther) == typeof(double))
{
double actualValue = (double)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (int)actualValue;
#else
result = (int)actualValue;
#endif
return true;
}
else if (typeof(TOther) == typeof(Half))
Expand Down Expand Up @@ -1124,8 +1136,12 @@ private static bool TryConvertFromTruncating<TOther>(TOther value, out int resul
else if (typeof(TOther) == typeof(float))
{
float actualValue = (float)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (int)actualValue;
#else
result = (int)actualValue;
#endif
return true;
}
else
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Int64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,12 @@ private static bool TryConvertFromSaturating<TOther>(TOther value, out long resu
if (typeof(TOther) == typeof(double))
{
double actualValue = (double)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (long)actualValue;
#else
result = (long)actualValue;
#endif
return true;
}
else if (typeof(TOther) == typeof(Half))
Expand Down Expand Up @@ -1044,8 +1048,12 @@ private static bool TryConvertFromSaturating<TOther>(TOther value, out long resu
else if (typeof(TOther) == typeof(float))
{
float actualValue = (float)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (long)actualValue;
#else
result = (long)actualValue;
#endif
return true;
}
else
Expand Down Expand Up @@ -1075,8 +1083,12 @@ private static bool TryConvertFromTruncating<TOther>(TOther value, out long resu
if (typeof(TOther) == typeof(double))
{
double actualValue = (double)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (long)actualValue;
#else
result = (long)actualValue;
#endif
return true;
}
else if (typeof(TOther) == typeof(Half))
Expand Down Expand Up @@ -1119,8 +1131,12 @@ private static bool TryConvertFromTruncating<TOther>(TOther value, out long resu
else if (typeof(TOther) == typeof(float))
{
float actualValue = (float)(object)value;
#if MONO
result = (actualValue >= MaxValue) ? MaxValue :
(actualValue <= MinValue) ? MinValue : (long)actualValue;
#else
result = (long)actualValue;
#endif
return true;
}
else
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/IntPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,12 @@ private static bool TryConvertFromSaturating<TOther>(TOther value, out nint resu
if (typeof(TOther) == typeof(double))
{
double actualValue = (double)(object)value;
#if MONO
result = (actualValue >= nint_t.MaxValue) ? unchecked((nint)nint_t.MaxValue) :
(actualValue <= nint_t.MinValue) ? unchecked((nint)nint_t.MinValue) : (nint)actualValue;
#else
result = (nint)actualValue;
#endif
return true;
}
else if (typeof(TOther) == typeof(Half))
Expand Down Expand Up @@ -1040,8 +1044,12 @@ private static bool TryConvertFromSaturating<TOther>(TOther value, out nint resu
else if (typeof(TOther) == typeof(float))
{
float actualValue = (float)(object)value;
#if MONO
result = (actualValue >= nint_t.MaxValue) ? unchecked((nint)nint_t.MaxValue) :
(actualValue <= nint_t.MinValue) ? unchecked((nint)nint_t.MinValue) : (nint)actualValue;
#else
result = (nint)actualValue;
#endif
return true;
}
else
Expand Down Expand Up @@ -1071,8 +1079,12 @@ private static bool TryConvertFromTruncating<TOther>(TOther value, out nint resu
if (typeof(TOther) == typeof(double))
{
double actualValue = (double)(object)value;
#if MONO
result = (actualValue >= nint_t.MaxValue) ? unchecked((nint)nint_t.MaxValue) :
(actualValue <= nint_t.MinValue) ? unchecked((nint)nint_t.MinValue) : (nint)actualValue;
#else
result = (nint)actualValue;
#endif
return true;
}
else if (typeof(TOther) == typeof(Half))
Expand Down Expand Up @@ -1115,8 +1127,12 @@ private static bool TryConvertFromTruncating<TOther>(TOther value, out nint resu
else if (typeof(TOther) == typeof(float))
{
float actualValue = (float)(object)value;
#if MONO
result = (actualValue >= nint_t.MaxValue) ? unchecked((nint)nint_t.MaxValue) :
(actualValue <= nint_t.MinValue) ? unchecked((nint)nint_t.MinValue) : (nint)actualValue;
#else
result = (nint)actualValue;
#endif
return true;
}
else
Expand Down
16 changes: 13 additions & 3 deletions src/libraries/System.Private.CoreLib/src/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,16 +1439,24 @@ private static bool TryConvertTo<TOther>(float value, [MaybeNullWhen(false)] out
}
else if (typeof(TOther) == typeof(uint))
{
#if MONO
uint actualResult = (value >= uint.MaxValue) ? uint.MaxValue :
(value <= uint.MinValue) ? uint.MinValue : (uint)value;
#else
uint actualResult = (uint)value;
#endif
result = (TOther)(object)actualResult;
return true;
}
else if (typeof(TOther) == typeof(ulong))
{
#if MONO
ulong actualResult = (value >= ulong.MaxValue) ? ulong.MaxValue :
(value <= ulong.MinValue) ? ulong.MinValue :
IsNaN(value) ? 0 : (ulong)value;
#else
ulong actualResult = (ulong)value;
#endif
result = (TOther)(object)actualResult;
return true;
}
Expand All @@ -1461,17 +1469,19 @@ private static bool TryConvertTo<TOther>(float value, [MaybeNullWhen(false)] out
}
else if (typeof(TOther) == typeof(nuint))
{
#if MONO
#if TARGET_64BIT
nuint actualResult = (value >= ulong.MaxValue) ? unchecked((nuint)ulong.MaxValue) :
(value <= ulong.MinValue) ? unchecked((nuint)ulong.MinValue) : (nuint)value;
result = (TOther)(object)actualResult;
return true;
#else
nuint actualResult = (value >= uint.MaxValue) ? uint.MaxValue :
(value <= uint.MinValue) ? uint.MinValue : (nuint)value;
#endif
#else
nuint actualResult = (nuint)value;
#endif
result = (TOther)(object)actualResult;
return true;
#endif
}
else
{
Expand Down
Loading