This is an old version, view current version.

13.13 Real values in coditionals

Deprecated: Using a real value in a conditional

real x = 1.0;
if (x) {

The value is interpreted as true if it is nonzero.

Replacement: For the exact equivalent, use a comparison operator to make the intent clear.

real x = 1.0;
if (x != 0) {

However, one should keep in mind that floating point calculations are subject to rounding errors and precise equality is fragile. It is worth considering whether the more robust alternative abs(x) < machine_precision() is appropriate for the use case.

Scheduled Removal: Stan 2.34