public static double IEEERemainder (double x, double y)
{
double r;
if (y == 0)
return Double.NaN;
r = x - (y * Math.Round(x/y));
if (r != 0)
return r;
/* Int64BitsToDouble is not endian-aware, but that is fine here */
return (x > 0) ? 0: (BitConverter.Int64BitsToDouble (Int64.MinValue));
}