2019-08-23 11:56:54 -07:00
|
|
|
namespace System
|
|
|
|
{
|
2020-08-10 13:27:48 -07:00
|
|
|
#unwarn
|
2020-08-29 07:10:04 -07:00
|
|
|
struct UInt : uint, IInteger, IUnsigned, IHashable, IFormattable, IIsNaN
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
|
|
|
public enum ParseError
|
|
|
|
{
|
|
|
|
case Ok;
|
|
|
|
case NoValue;
|
2023-05-14 16:54:26 -03:00
|
|
|
case Overflow;
|
2019-08-23 11:56:54 -07:00
|
|
|
case InvalidChar(uint partialResult);
|
|
|
|
}
|
|
|
|
|
2023-05-14 16:54:26 -03:00
|
|
|
public const uint MaxValue = (sizeof(uint) == 8) ? 0xFFFFFFFFFFFFFFFFUL : 0xFFFFFFFFL;
|
|
|
|
public const uint MinValue = 0;
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
public bool IsNull()
|
|
|
|
{
|
|
|
|
return this == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int operator<=>(UInt a, UInt b)
|
|
|
|
{
|
|
|
|
return (int)a <=> (int)b;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Self operator+(Self lhs, Self rhs)
|
|
|
|
{
|
|
|
|
return (SelfBase)lhs + (SelfBase)rhs;
|
|
|
|
}
|
|
|
|
|
2020-03-20 22:01:18 +00:00
|
|
|
public static Self operator-(Self lhs, Self rhs)
|
|
|
|
{
|
|
|
|
return (SelfBase)lhs - (SelfBase)rhs;
|
|
|
|
}
|
|
|
|
|
2020-06-05 15:46:31 +02:00
|
|
|
public static Self operator*(Self lhs, Self rhs)
|
|
|
|
{
|
|
|
|
return (SelfBase)lhs * (SelfBase)rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Self operator/(Self lhs, Self rhs)
|
|
|
|
{
|
|
|
|
return (SelfBase)lhs / (SelfBase)rhs;
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:41:14 -08:00
|
|
|
public int GetHashCode()
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
|
|
|
return (int)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IIsNaN.IsNaN
|
|
|
|
{
|
|
|
|
[SkipCall]
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void ToString(String strBuffer)
|
|
|
|
{
|
|
|
|
if (sizeof(Self) == sizeof(uint64))
|
|
|
|
((uint64)this).ToString(strBuffer);
|
|
|
|
else
|
|
|
|
((uint32)this).ToString(strBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ToString(String outString, String format, IFormatProvider formatProvider)
|
|
|
|
{
|
|
|
|
if (sizeof(Self) == sizeof(uint64))
|
|
|
|
((uint64)this).ToString(outString, format, formatProvider);
|
|
|
|
else
|
|
|
|
((uint32)this).ToString(outString, format, formatProvider);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Result<uint, ParseError> Parse(StringView val)
|
|
|
|
{
|
|
|
|
if (sizeof(Self) == sizeof(uint64))
|
|
|
|
{
|
|
|
|
var result = UInt64.Parse(val);
|
|
|
|
return *(Result<uint, ParseError>*)&result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-03 06:50:25 -07:00
|
|
|
var result = UInt32.Parse(val);
|
2019-08-23 11:56:54 -07:00
|
|
|
return *(Result<uint, ParseError>*)&result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|