2.5 Casting functions

It is possible to cast real numbers to integers as long as the real value is data. See data only qualifiers in the Stan Reference Manual.

int to_int(data real x)

Return the value x truncated to an integer. This will throw an error if the value of x is too big to represent as a 32-bit signed integer.

This is similar to trunc (see Rounding functions) but the return type is of type int. For example, to_int(3.9) is 3, and to_int(-3.9) is -3.
Available since 2.31

I to_int(data T x)

The vectorized version of to_int. This function accepts a (possibly nested) array of reals and returns an array of the same shape where each element has been truncated to an integer.
Available since 2.31