On 11/28/13, 2:57 PM, FHRB Toledo wrote:
> Thank you Bob,
>
> In this thread, is there a way to declare casting type within Stan?
I'm not sure what you're asking for.
If you have:
int n;
int m;
double frac;
frac <- n / m;
then it's probably not going to do what you expect if
your expectations come from R, where "1/4" evaluates to 0.25.
In Stan, "1/4" evaluates to 0.
If you want to force a double-based division on two
integers, you can rely on promotion:
frac <- n;
frac <- frac / m;
We don't have any plans to add C-style or C++-style casts.
> Just to avoid "semantic" errors in the same way as
> in C++ native code!
int / int is defined to return an int, so it's
a feature, not an error, semantic or otherwise.
It absolutely needs to be this way in order to preserve return
types and bottom-up evaluations. Expressions like "m / n" get evaluated
bottom-up in the sense that they don't depend on the return type.
My understanding is that in R, everything's underlyingly a double.
- Bob