Integer to real conversion in stan SOLVED

Sorry if this is a dumb question. I have a stan model which runs loops in the transformed parameters and generated quantities sections. I want to calculate the fraction of the loop that has run.

 for (n in 1:ndate) {

    alpha = (n-1)/(ndate-1);

where n and ndate are integers. But I get this message.

DIAGNOSTIC(S) FROM PARSER:
Info: integer division implicitly rounds to integer. Found int division: (n - 1) / (ndate - 1)
 Positive values rounded down, negative values rounded up or down in platform-dependent way.

I’ve looked around but I can’t figure out how to coerce these integers to real values. There is an old github issue here but it doesn’t seem to have been implemented?

Edit: Nevermind, I changed 1 to 1.0, and it did the job.

Thanks.

to_vector function can work?

1 Like