lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Mar 31, 2014 at 9:58 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> It can be improved by changing the formula used by Lua to calculate modulo.

Any suggestion?

-- Roberto


double modulo4Lua (double x, double y)
{
   double m = fmod(x, y);
   if ((m != 0.0) && (x*y < 0.0))
      return y + m;
   else
      return m;
}


http://codepad.org/tMF0feBW