mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 21:09:53 +00:00
Made some basic staff.
This commit is contained in:
216
src/SVM.Core/Data/CompactByte.cs
Normal file
216
src/SVM.Core/Data/CompactByte.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace SVM.Core.Data
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CompactByte : INumbericData<CompactByte>
|
||||
{
|
||||
public byte Value;
|
||||
public CompactByte(byte value) { Value = value; }
|
||||
public CompactByte(int value) { Value = (byte)value; }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public CompactByte Add(CompactByte R)
|
||||
{
|
||||
return new CompactByte(Value + R.Value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public CompactByte Sub(CompactByte R)
|
||||
{
|
||||
return new CompactByte(Value - R.Value);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public CompactByte Mul(CompactByte R)
|
||||
{
|
||||
return new CompactByte(Value * R.Value);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public CompactByte Div(CompactByte R)
|
||||
{
|
||||
return new CompactByte(Value / R.Value);
|
||||
}
|
||||
public SCVMSimpleResult<CompactByte> AddOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
checked
|
||||
{
|
||||
try
|
||||
{
|
||||
result = new CompactByte(Value + R.Value);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
IsOF = true;
|
||||
result = new CompactByte(Value + R.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactByte> SubOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
checked
|
||||
{
|
||||
try
|
||||
{
|
||||
result = new CompactByte(Value - R.Value);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
IsOF = true;
|
||||
result = new CompactByte(Value - R.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactByte> DivOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
checked
|
||||
{
|
||||
try
|
||||
{
|
||||
result = new CompactByte(Value / R.Value);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
IsOF = true;
|
||||
result = new CompactByte(Value / R.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public SCVMSimpleResult<CompactByte> MulOF(CompactByte R)
|
||||
{
|
||||
CompactByte result = default;
|
||||
bool IsOF = false;
|
||||
checked
|
||||
{
|
||||
try
|
||||
{
|
||||
result = new CompactByte(Value * R.Value);
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
IsOF = true;
|
||||
result = new CompactByte(Value * R.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SCVMSimpleResult<CompactByte>(IsOF, result);
|
||||
}
|
||||
|
||||
public bool LT(CompactByte R)
|
||||
{
|
||||
return Value < R.Value;
|
||||
}
|
||||
|
||||
public bool GT(CompactByte R)
|
||||
{
|
||||
return Value > R.Value;
|
||||
}
|
||||
|
||||
public bool LE(CompactByte R)
|
||||
{
|
||||
return Value <= R.Value;
|
||||
}
|
||||
|
||||
public bool GE(CompactByte R)
|
||||
{
|
||||
return Value >= R.Value;
|
||||
}
|
||||
|
||||
public bool EQ(CompactByte R)
|
||||
{
|
||||
return Value == R.Value;
|
||||
}
|
||||
|
||||
public bool NE(CompactByte R)
|
||||
{
|
||||
return Value != R.Value;
|
||||
}
|
||||
|
||||
public INumbericData<CompactByte> Cast_Byte()
|
||||
{
|
||||
return new CompactByte(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactSByte> Cast_SByte()
|
||||
{
|
||||
return new CompactSByte((sbyte)Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactShort> Cast_Short()
|
||||
{
|
||||
return new CompactShort(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactUShort> Cast_UShort()
|
||||
{
|
||||
return new CompactUShort(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactInt> Cast_Int()
|
||||
{
|
||||
return new CompactInt(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactUInt> Cast_UInt()
|
||||
{
|
||||
return new CompactUInt(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactLong> Cast_Long()
|
||||
{
|
||||
return new CompactLong(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactULong> Cast_ULong()
|
||||
{
|
||||
return new CompactULong(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactDouble> Cast_Double()
|
||||
{
|
||||
return new CompactDouble(Value);
|
||||
}
|
||||
|
||||
public INumbericData<CompactSingle> Cast_Float()
|
||||
{
|
||||
return new CompactSingle(Value);
|
||||
}
|
||||
public unsafe void Write(byte* targetPtr)
|
||||
{
|
||||
targetPtr[0] = Value;
|
||||
}
|
||||
public int SizeOf()
|
||||
{
|
||||
return sizeof(byte);
|
||||
}
|
||||
|
||||
public CompactByte Mod(CompactByte R)
|
||||
{
|
||||
return new CompactByte(Value % R.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user