Problem with ceil function

Hi,

I have the following formula:

real custom_function(int n,  int m) {
   int turn;

   for (i in 1:n) {
      turn  = ceil(i / m) % m;

      if (turn) {
          // do something
      } else {
          // do something else
      }
   }
}

This yields the following error:

Ill-typed arguments supplied to infix operator %. Available signatures:
(int, int) => int
Instead supplied arguments of incompatible type: real, int.

In the docs I see that the input parameter of ceil should be a real, but the code below also gives the same error:

  turn  = ceil(1.0 * i / m) % m;

Any advice? Thanks

The problem is that the output of ceil is considered to be a real and thus cannot be assigned to an int.
Possible workaround:

real custom_function(int n,  int m) {
   int turn;
   int c = 1; // ceil(i / m)

   for (i in 1:n) {
      turn  = c % m;
      if (i % m == 0) {
        c += 1; // for the next iteration
      }

      if (turn) {
          // do something
      } else {
          // do something else
      }
   }
}