public static float Decompress (ushort value) {return (float)value / (float)(ushort.MaxValue);}
public static ushort Compress (float value)
if (value > 1.0f) value = 1.0f;
if (value < 0.0f) value = 0.0f;
return (ushort)(value * (float)(ushort.MaxValue));
public static bool IsStable (ushort value) {return value == Compress(Decompress(value));}
public static void Main()
for (ushort v = 0; v < ushort.MaxValue; v ++) count += IsStable(v) ? 1 : 0;
Console.WriteLine("Stable values " + count);