[ create a new paste ] login | about

Link: http://codepad.org/tMF0feBW    [ raw code | output | fork ]

C, pasted on Apr 6:
#include <stdio.h>
#include <math.h>

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;
}

int main ()
{
   printf("%f\n%f\n%f\n%f\n%f\n%f\n%f\n", 
      modulo4Lua(5.5,  1.0/0.0),
      modulo4Lua(-5.5, 1.0/0.0),
      modulo4Lua(-4.0, -2.0),
      modulo4Lua( 4.0,  3.0),
      modulo4Lua(-4.0,  3.0),
      modulo4Lua( 4.0, -3.0),
      modulo4Lua(-4.0, -3.0)
   );
   return(0);
}


Output:
1
2
3
4
5
6
7
5.500000
inf
-0.000000
1.000000
2.000000
-2.000000
-1.000000


Create a new paste based on this one


Comments: