mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-02-04 05:36:05 +00:00
144 lines
4.1 KiB
C#
144 lines
4.1 KiB
C#
namespace SabreTools.Numerics
|
|
{
|
|
/// <summary>
|
|
/// Both-endian 64-bit signed value
|
|
/// </summary>
|
|
public sealed class BothInt64(long le, long be) : BothEndian<long>(le, be)
|
|
{
|
|
public static implicit operator BothInt64(long val)
|
|
=> new(val, val);
|
|
|
|
#region Arithmetic Unary Operators
|
|
|
|
public static BothInt64 operator ++(BothInt64 a)
|
|
{
|
|
long le = a.LittleEndian + 1;
|
|
long be = a.BigEndian + 1;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator --(BothInt64 a)
|
|
{
|
|
long le = a.LittleEndian - 1;
|
|
long be = a.BigEndian - 1;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator +(BothInt64 a)
|
|
{
|
|
long le = +a.LittleEndian;
|
|
long be = +a.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator -(BothInt64 a)
|
|
{
|
|
long le = -a.LittleEndian;
|
|
long be = -a.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Arithmetic Binary Operators
|
|
|
|
public static BothInt64 operator *(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian * b.LittleEndian;
|
|
long be = a.BigEndian * b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator /(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian / b.LittleEndian;
|
|
long be = a.BigEndian / b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator %(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian % b.LittleEndian;
|
|
long be = a.BigEndian % b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator +(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian + b.LittleEndian;
|
|
long be = a.BigEndian + b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator -(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian - b.LittleEndian;
|
|
long be = a.BigEndian - b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Bitwise Unary Operators
|
|
|
|
public static BothInt64 operator ~(BothInt64 a)
|
|
{
|
|
long le = ~a.LittleEndian;
|
|
long be = ~a.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Shift Binary Operators
|
|
|
|
public static BothInt64 operator <<(BothInt64 a, BothInt32 b)
|
|
{
|
|
long le = a.LittleEndian << b.LittleEndian;
|
|
long be = a.BigEndian << b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator >>(BothInt64 a, BothInt32 b)
|
|
{
|
|
long le = a.LittleEndian >> b.LittleEndian;
|
|
long be = a.BigEndian >> b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator >>>(BothInt64 a, BothInt32 b)
|
|
{
|
|
long le = a.LittleEndian >>> b.LittleEndian;
|
|
long be = a.BigEndian >>> b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Bitwise Binary Operators
|
|
|
|
public static BothInt64 operator &(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian & b.LittleEndian;
|
|
long be = a.BigEndian & b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator |(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian | b.LittleEndian;
|
|
long be = a.BigEndian | b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
public static BothInt64 operator ^(BothInt64 a, BothInt64 b)
|
|
{
|
|
long le = a.LittleEndian ^ b.LittleEndian;
|
|
long be = a.BigEndian ^ b.BigEndian;
|
|
return new BothInt64(le, be);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|