using System.Runtime.CompilerServices; namespace RebootKit.Engine.Foundation { public static class QuantizationUtility { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort FloatToUShort(float value, float min, float max) { return (ushort)((value - min) / (max - min) * ushort.MaxValue); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float UShortToFloat(ushort value, float min, float max) { return min + (value / (float)ushort.MaxValue) * (max - min); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte FloatToByte(float value, float min, float max) { return (byte)((value - min) / (max - min) * byte.MaxValue); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float ByteToFloat(byte value, float min, float max) { return min + (value / (float)byte.MaxValue) * (max - min); } } }