Corrected operators for uchar to use the internal type for operations, defined int8_t compat type

This commit is contained in:
Samuele Lorefice
2025-01-22 16:29:54 +01:00
parent 0a51b6e052
commit d5533ac251
2 changed files with 43 additions and 12 deletions

View File

@@ -0,0 +1,31 @@
namespace BlendFile.CompatTypes;
public readonly struct int8_t {
public int8_t Value => _value;
private readonly sbyte _value;
public int8_t(sbyte value) => _value = value;
public int8_t(int8_t value) => _value = (sbyte)value._value;
public static explicit operator sbyte(int8_t value) => value._value;
public static implicit operator int8_t(sbyte value) => new(value);
public static explicit operator byte(int8_t value) => (byte)value._value;
public static implicit operator int8_t(byte value) => new((sbyte)value);
public static explicit operator int(int8_t value) => value._value;
public static implicit operator int8_t(int value) => new((sbyte)value);
public static int8_t operator +(int8_t left, int8_t right) => left._value + right._value;
public static int8_t operator -(int8_t left, int8_t right) => left._value - right._value;
public static int8_t operator *(int8_t left, int8_t right) => left._value * right._value;
public static int8_t operator /(int8_t left, int8_t right) => left._value / right._value;
public static int8_t operator %(int8_t left, int8_t right) => left._value % right._value;
public static int8_t operator &(int8_t left, int8_t right) => left._value & right._value;
public static int8_t operator |(int8_t left, int8_t right) => left._value | right._value;
public static int8_t operator ^(int8_t left, int8_t right) => left._value ^ right._value;
public static int8_t operator <<(int8_t left, int right) => left._value << right;
public static int8_t operator >>(int8_t left, int right) => left._value >> right;
public static int8_t operator ++(int8_t value) => new (value._value + 1);
public static int8_t operator --(int8_t value) => new (value._value - 1);
}

View File

@@ -19,16 +19,16 @@ public readonly struct uchar {
public static explicit operator int(uchar value) => value._value;
public static implicit operator uchar(int value) => new((byte)value);
public static uchar operator +(uchar left, uchar right) => left.Value + right.Value;
public static uchar operator -(uchar left, uchar right) => left.Value - right.Value;
public static uchar operator *(uchar left, uchar right) => left.Value * right.Value;
public static uchar operator /(uchar left, uchar right) => left.Value / right.Value;
public static uchar operator %(uchar left, uchar right) => left.Value % right.Value;
public static uchar operator &(uchar left, uchar right) => left.Value & right.Value;
public static uchar operator |(uchar left, uchar right) => left.Value | right.Value;
public static uchar operator ^(uchar left, uchar right) => left.Value ^ right.Value;
public static uchar operator <<(uchar left, byte right) => left.Value << right;
public static uchar operator >>(uchar left, byte right) => left.Value >> right;
public static uchar operator ++(uchar value) => new (value.Value + 1);
public static uchar operator --(uchar value) => new (value.Value - 1);
public static uchar operator +(uchar left, uchar right) => left._value + right._value;
public static uchar operator -(uchar left, uchar right) => left._value - right._value;
public static uchar operator *(uchar left, uchar right) => left._value * right._value;
public static uchar operator /(uchar left, uchar right) => left._value / right._value;
public static uchar operator %(uchar left, uchar right) => left._value % right._value;
public static uchar operator &(uchar left, uchar right) => left._value & right._value;
public static uchar operator |(uchar left, uchar right) => left._value | right._value;
public static uchar operator ^(uchar left, uchar right) => left._value ^ right._value;
public static uchar operator <<(uchar left, byte right) => left._value << right;
public static uchar operator >>(uchar left, byte right) => left._value >> right;
public static uchar operator ++(uchar value) => new (value._value + 1);
public static uchar operator --(uchar value) => new (value._value - 1);
}