Add base type operator support to both-endian

This commit is contained in:
Matt Nadareski
2025-10-27 14:02:52 -04:00
parent 2b6fc200e2
commit 5b306ce9e8
8 changed files with 282 additions and 2 deletions

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothInt16(le, be);
}
public static BothInt16 operator +(BothInt16 a, short b)
{
short le = (short)(a.LittleEndian + b);
short be = (short)(a.BigEndian + b);
return new BothInt16(le, be);
}
public static BothInt16 operator -(BothInt16 a, BothInt16 b)
{
short le = (short)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothInt16(le, be);
}
public static BothInt16 operator -(BothInt16 a, short b)
{
short le = (short)(a.LittleEndian - b);
short be = (short)(a.BigEndian - b);
return new BothInt16(le, be);
}
public static BothInt16 operator *(BothInt16 a, BothInt16 b)
{
short le = (short)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothInt16(le, be);
}
public static BothInt16 operator *(BothInt16 a, short b)
{
short le = (short)(a.LittleEndian * b);
short be = (short)(a.BigEndian * b);
return new BothInt16(le, be);
}
public static BothInt16 operator /(BothInt16 a, BothInt16 b)
{
short le = (short)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothInt16(le, be);
}
public static BothInt16 operator /(BothInt16 a, short b)
{
short le = (short)(a.LittleEndian / b);
short be = (short)(a.BigEndian / b);
return new BothInt16(le, be);
}
public static BothInt16 operator ^(BothInt16 a, BothInt16 b)
{
short le = (short)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothInt16(le, be);
}
public static BothInt16 operator ^(BothInt16 a, short b)
{
short le = (short)(a.LittleEndian ^ b);
short be = (short)(a.BigEndian ^ b);
return new BothInt16(le, be);
}
public static implicit operator BothInt16(short val)
=> new(val, val);

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothInt32(le, be);
}
public static BothInt32 operator +(BothInt32 a, int b)
{
int le = (int)(a.LittleEndian + b);
int be = (int)(a.BigEndian + b);
return new BothInt32(le, be);
}
public static BothInt32 operator -(BothInt32 a, BothInt32 b)
{
int le = (int)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothInt32(le, be);
}
public static BothInt32 operator -(BothInt32 a, int b)
{
int le = (int)(a.LittleEndian - b);
int be = (int)(a.BigEndian - b);
return new BothInt32(le, be);
}
public static BothInt32 operator *(BothInt32 a, BothInt32 b)
{
int le = (int)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothInt32(le, be);
}
public static BothInt32 operator *(BothInt32 a, int b)
{
int le = (int)(a.LittleEndian * b);
int be = (int)(a.BigEndian * b);
return new BothInt32(le, be);
}
public static BothInt32 operator /(BothInt32 a, BothInt32 b)
{
int le = (int)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothInt32(le, be);
}
public static BothInt32 operator /(BothInt32 a, int b)
{
int le = (int)(a.LittleEndian / b);
int be = (int)(a.BigEndian / b);
return new BothInt32(le, be);
}
public static BothInt32 operator ^(BothInt32 a, BothInt32 b)
{
int le = (int)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothInt32(le, be);
}
public static BothInt32 operator ^(BothInt32 a, int b)
{
int le = (int)(a.LittleEndian ^ b);
int be = (int)(a.BigEndian ^ b);
return new BothInt32(le, be);
}
public static implicit operator BothInt32(int val)
=> new(val, val);

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothInt64(le, be);
}
public static BothInt64 operator +(BothInt64 a, long b)
{
long le = (long)(a.LittleEndian + b);
long be = (long)(a.BigEndian + b);
return new BothInt64(le, be);
}
public static BothInt64 operator -(BothInt64 a, BothInt64 b)
{
long le = (long)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothInt64(le, be);
}
public static BothInt64 operator -(BothInt64 a, long b)
{
long le = (long)(a.LittleEndian - b);
long be = (long)(a.BigEndian - b);
return new BothInt64(le, be);
}
public static BothInt64 operator *(BothInt64 a, BothInt64 b)
{
long le = (long)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothInt64(le, be);
}
public static BothInt64 operator *(BothInt64 a, long b)
{
long le = (long)(a.LittleEndian * b);
long be = (long)(a.BigEndian * b);
return new BothInt64(le, be);
}
public static BothInt64 operator /(BothInt64 a, BothInt64 b)
{
long le = (long)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothInt64(le, be);
}
public static BothInt64 operator /(BothInt64 a, long b)
{
long le = (long)(a.LittleEndian / b);
long be = (long)(a.BigEndian / b);
return new BothInt64(le, be);
}
public static BothInt64 operator ^(BothInt64 a, BothInt64 b)
{
long le = (long)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothInt64(le, be);
}
public static BothInt64 operator ^(BothInt64 a, long b)
{
long le = (long)(a.LittleEndian ^ b);
long be = (long)(a.BigEndian ^ b);
return new BothInt64(le, be);
}
public static implicit operator BothInt64(long val)
=> new(val, val);

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothInt8(le, be);
}
public static BothInt8 operator +(BothInt8 a, sbyte b)
{
sbyte le = (sbyte)(a.LittleEndian + b);
sbyte be = (sbyte)(a.BigEndian + b);
return new BothInt8(le, be);
}
public static BothInt8 operator -(BothInt8 a, BothInt8 b)
{
sbyte le = (sbyte)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothInt8(le, be);
}
public static BothInt8 operator -(BothInt8 a, sbyte b)
{
sbyte le = (sbyte)(a.LittleEndian - b);
sbyte be = (sbyte)(a.BigEndian - b);
return new BothInt8(le, be);
}
public static BothInt8 operator *(BothInt8 a, BothInt8 b)
{
sbyte le = (sbyte)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothInt8(le, be);
}
public static BothInt8 operator *(BothInt8 a, sbyte b)
{
sbyte le = (sbyte)(a.LittleEndian * b);
sbyte be = (sbyte)(a.BigEndian * b);
return new BothInt8(le, be);
}
public static BothInt8 operator /(BothInt8 a, BothInt8 b)
{
sbyte le = (sbyte)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothInt8(le, be);
}
public static BothInt8 operator /(BothInt8 a, sbyte b)
{
sbyte le = (sbyte)(a.LittleEndian / b);
sbyte be = (sbyte)(a.BigEndian / b);
return new BothInt8(le, be);
}
public static BothInt8 operator ^(BothInt8 a, BothInt8 b)
{
sbyte le = (sbyte)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothInt8(le, be);
}
public static BothInt8 operator ^(BothInt8 a, sbyte b)
{
sbyte le = (sbyte)(a.LittleEndian ^ b);
sbyte be = (sbyte)(a.BigEndian ^ b);
return new BothInt8(le, be);
}
public static implicit operator BothInt8(sbyte val)
=> new(val, val);

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt16(le, be);
}
public static BothUInt16 operator +(BothUInt16 a, ushort b)
{
ushort le = (ushort)(a.LittleEndian + b);
ushort be = (ushort)(a.BigEndian + b);
return new BothUInt16(le, be);
}
public static BothUInt16 operator -(BothUInt16 a, BothUInt16 b)
{
ushort le = (ushort)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt16(le, be);
}
public static BothUInt16 operator -(BothUInt16 a, ushort b)
{
ushort le = (ushort)(a.LittleEndian - b);
ushort be = (ushort)(a.BigEndian - b);
return new BothUInt16(le, be);
}
public static BothUInt16 operator *(BothUInt16 a, BothUInt16 b)
{
ushort le = (ushort)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt16(le, be);
}
public static BothUInt16 operator *(BothUInt16 a, ushort b)
{
ushort le = (ushort)(a.LittleEndian * b);
ushort be = (ushort)(a.BigEndian * b);
return new BothUInt16(le, be);
}
public static BothUInt16 operator /(BothUInt16 a, BothUInt16 b)
{
ushort le = (ushort)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt16(le, be);
}
public static BothUInt16 operator /(BothUInt16 a, ushort b)
{
ushort le = (ushort)(a.LittleEndian / b);
ushort be = (ushort)(a.BigEndian / b);
return new BothUInt16(le, be);
}
public static BothUInt16 operator ^(BothUInt16 a, BothUInt16 b)
{
ushort le = (ushort)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt16(le, be);
}
public static BothUInt16 operator ^(BothUInt16 a, ushort b)
{
ushort le = (ushort)(a.LittleEndian ^ b);
ushort be = (ushort)(a.BigEndian ^ b);
return new BothUInt16(le, be);
}
public static implicit operator BothUInt16(ushort val)
=> new(val, val);

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt32(le, be);
}
public static BothUInt32 operator +(BothUInt32 a, uint b)
{
uint le = (uint)(a.LittleEndian + b);
uint be = (uint)(a.BigEndian + b);
return new BothUInt32(le, be);
}
public static BothUInt32 operator -(BothUInt32 a, BothUInt32 b)
{
uint le = (uint)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt32(le, be);
}
public static BothUInt32 operator -(BothUInt32 a, uint b)
{
uint le = (uint)(a.LittleEndian - b);
uint be = (uint)(a.BigEndian - b);
return new BothUInt32(le, be);
}
public static BothUInt32 operator *(BothUInt32 a, BothUInt32 b)
{
uint le = (uint)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt32(le, be);
}
public static BothUInt32 operator *(BothUInt32 a, uint b)
{
uint le = (uint)(a.LittleEndian * b);
uint be = (uint)(a.BigEndian * b);
return new BothUInt32(le, be);
}
public static BothUInt32 operator /(BothUInt32 a, BothUInt32 b)
{
uint le = (uint)(a.LittleEndian / b.LittleEndian);
@@ -35,10 +56,24 @@ namespace SabreTools.IO.Numerics
return new BothUInt32(le, be);
}
public static BothUInt32 operator /(BothUInt32 a, uint b)
{
uint le = (uint)(a.LittleEndian / b);
uint be = (uint)(a.BigEndian / b);
return new BothUInt32(le, be);
}
public static BothUInt32 operator ^(BothUInt32 a, BothUInt32 b)
{
uint le = (uint)(a.LittleEndian ^ b.LittleEndian);
uint be = (uint)(a.BigEndian ^ b.BigEndian);
uint le = (uint)(a.LittleEndian ^ b);
uint be = (uint)(a.BigEndian ^ b);
return new BothUInt32(le, be);
}
public static BothUInt32 operator ^(BothUInt32 a, uint b)
{
uint le = (uint)(a.LittleEndian ^ b);
uint be = (uint)(a.BigEndian ^ b);
return new BothUInt32(le, be);
}

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt64(le, be);
}
public static BothUInt64 operator +(BothUInt64 a, ulong b)
{
ulong le = (ulong)(a.LittleEndian + b);
ulong be = (ulong)(a.BigEndian + b);
return new BothUInt64(le, be);
}
public static BothUInt64 operator -(BothUInt64 a, BothUInt64 b)
{
ulong le = (ulong)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt64(le, be);
}
public static BothUInt64 operator -(BothUInt64 a, ulong b)
{
ulong le = (ulong)(a.LittleEndian - b);
ulong be = (ulong)(a.BigEndian - b);
return new BothUInt64(le, be);
}
public static BothUInt64 operator *(BothUInt64 a, BothUInt64 b)
{
ulong le = (ulong)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt64(le, be);
}
public static BothUInt64 operator *(BothUInt64 a, ulong b)
{
ulong le = (ulong)(a.LittleEndian * b);
ulong be = (ulong)(a.BigEndian * b);
return new BothUInt64(le, be);
}
public static BothUInt64 operator /(BothUInt64 a, BothUInt64 b)
{
ulong le = (ulong)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt64(le, be);
}
public static BothUInt64 operator /(BothUInt64 a, ulong b)
{
ulong le = (ulong)(a.LittleEndian / b);
ulong be = (ulong)(a.BigEndian / b);
return new BothUInt64(le, be);
}
public static BothUInt64 operator ^(BothUInt64 a, BothUInt64 b)
{
ulong le = (ulong)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt64(le, be);
}
public static BothUInt64 operator ^(BothUInt64 a, ulong b)
{
ulong le = (ulong)(a.LittleEndian ^ b);
ulong be = (ulong)(a.BigEndian ^ b);
return new BothUInt64(le, be);
}
public static implicit operator BothUInt64(ulong val)
=> new(val, val);

View File

@@ -14,6 +14,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt8(le, be);
}
public static BothUInt8 operator +(BothUInt8 a, byte b)
{
byte le = (byte)(a.LittleEndian + b);
byte be = (byte)(a.BigEndian + b);
return new BothUInt8(le, be);
}
public static BothUInt8 operator -(BothUInt8 a, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian - b.LittleEndian);
@@ -21,6 +28,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt8(le, be);
}
public static BothUInt8 operator -(BothUInt8 a, byte b)
{
byte le = (byte)(a.LittleEndian - b);
byte be = (byte)(a.BigEndian - b);
return new BothUInt8(le, be);
}
public static BothUInt8 operator *(BothUInt8 a, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian * b.LittleEndian);
@@ -28,6 +42,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt8(le, be);
}
public static BothUInt8 operator *(BothUInt8 a, byte b)
{
byte le = (byte)(a.LittleEndian * b);
byte be = (byte)(a.BigEndian * b);
return new BothUInt8(le, be);
}
public static BothUInt8 operator /(BothUInt8 a, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian / b.LittleEndian);
@@ -35,6 +56,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt8(le, be);
}
public static BothUInt8 operator /(BothUInt8 a, byte b)
{
byte le = (byte)(a.LittleEndian / b);
byte be = (byte)(a.BigEndian / b);
return new BothUInt8(le, be);
}
public static BothUInt8 operator ^(BothUInt8 a, BothUInt8 b)
{
byte le = (byte)(a.LittleEndian ^ b.LittleEndian);
@@ -42,6 +70,13 @@ namespace SabreTools.IO.Numerics
return new BothUInt8(le, be);
}
public static BothUInt8 operator ^(BothUInt8 a, byte b)
{
byte le = (byte)(a.LittleEndian ^ b);
byte be = (byte)(a.BigEndian ^ b);
return new BothUInt8(le, be);
}
public static implicit operator BothUInt8(byte val)
=> new(val, val);