mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-19 16:40:26 +02:00
75 lines
1.5 KiB
Beef
75 lines
1.5 KiB
Beef
![]() |
namespace System
|
||
|
{
|
||
|
struct UInt : uint, IInteger, IUnsigned, IHashable, IOpComparable, IFormattable, IIsNaN, IOpAddable
|
||
|
{
|
||
|
public enum ParseError
|
||
|
{
|
||
|
case Ok;
|
||
|
case NoValue;
|
||
|
case InvalidChar(uint partialResult);
|
||
|
}
|
||
|
|
||
|
public const uint64 MaxValue = (sizeof(uint) == 8) ? 0xFFFFFFFFFFFFFFFFUL : 0xFFFFFFFFL;
|
||
|
public const uint64 MinValue = 0;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
int IHashable.GetHashCode()
|
||
|
{
|
||
|
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
|
||
|
{
|
||
|
var result = UInt64.Parse(val);
|
||
|
return *(Result<uint, ParseError>*)&result;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|