fazlurr
5/9/2015 - 11:37 AM

Fixing Negative Modulo in Java - http://stackoverflow.com/a/18994115

Fixing Negative Modulo in Java - http://stackoverflow.com/a/18994115

static double positiveRemainder(double n, double divisor)
{
  if (n >= 0)
    return n % divisor;
  else
  {
    double val = divisor + (n % divisor);
    if (val == divisor)
      return 0;
    else
      return val;
  }
}