private static double Ulp(double value)
{
if (Double.IsNaN(value)) return Double.NaN;
if (Double.IsInfinity(value)) return Double.PositiveInfinity;
if (value == +0.0d || value == -0.0d) return Double.MinValue;
if (value == Double.MaxValue) return Math.Pow(2, 971);
long bits = BitConverter.DoubleToInt64Bits(value);
double nextValue = BitConverter.Int64BitsToDouble(bits + 1);
return nextValue - value;
}