stanc3 icon indicating copy to clipboard operation
stanc3 copied to clipboard

Chained comparison

Open nhuurre opened this issue 4 years ago • 0 comments

What does this Stan code do?

if (x < y < z) {

The natural (naïve?) reading is that the condition asks if x < y and y < z and that is indeed how Python or Julia would interpret it. (R considers it a syntax error.) But Stan follows C/C++ convention where it reads (x < y) < z which is either 1 < z or 0 < z depending on whether or not x is less than y.

I think this should at least raise warning but preferably Stan could just implement comparison operators the same way Python and Julia do.

nhuurre avatar Feb 22 '21 18:02 nhuurre