2019-08-23 11:56:54 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace System
|
|
|
|
{
|
2020-08-10 13:27:48 -07:00
|
|
|
#unwarn
|
2020-08-29 07:10:04 -07:00
|
|
|
struct Int : int, IInteger, IHashable, IFormattable, IIsNaN
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
|
|
|
public enum ParseError
|
|
|
|
{
|
|
|
|
case Ok;
|
|
|
|
case NoValue;
|
|
|
|
case InvalidChar(int partialResult);
|
|
|
|
}
|
|
|
|
|
2020-08-29 07:10:04 -07:00
|
|
|
public const int MaxValue = (sizeof(uint) == 8) ? 0x7FFFFFFFFFFFFFFFL : 0x7FFFFFFF;
|
|
|
|
public const int MinValue = (sizeof(uint) == 8) ? -0x8000000000000000L : -0x80000000;
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public static int operator<=>(Self a, Self b)
|
|
|
|
{
|
|
|
|
return (SelfBase)a <=> (SelfBase)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;
|
|
|
|
}
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
public static Self operator-(Self value)
|
|
|
|
{
|
|
|
|
return (SelfBase)value;
|
|
|
|
}
|
|
|
|
|
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 void ToString(String outString, String format, IFormatProvider formatProvider)
|
|
|
|
{
|
|
|
|
if (sizeof(int) == sizeof(int64))
|
|
|
|
{
|
|
|
|
((int64)this).ToString(outString, format, formatProvider);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((int32)this).ToString(outString, format, formatProvider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void ToString(String outString)
|
|
|
|
{
|
|
|
|
if (sizeof(int) == sizeof(int64))
|
|
|
|
{
|
|
|
|
((int64)this).ToString(outString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((int32)this).ToString(outString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Result<int, ParseError> Parse(StringView val)
|
|
|
|
{
|
2020-07-03 06:50:25 -07:00
|
|
|
if (sizeof(Self) == sizeof(int64))
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
|
|
|
var result = Int64.Parse(val);
|
|
|
|
return *(Result<int, ParseError>*)&result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var result = Int32.Parse(val);
|
|
|
|
return *(Result<int, ParseError>*)&result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|