Float is an Inf and I can't use && to assign it a new value

Due to the relative priorities of infix operators && and =, this is parsed as

(isinf(sdmove) && sdmove) = 999.99

instead of what you really meant:

isinf(sdmove) && (sdmove = 999.9)

You can use this last expression in order to explicitly set the correct order of operations.


(Opinions on this may vary from one developer to another, but I personally tend to dislike short circuits in cases where the RHS is an assignment, precisely for that reason. But I do like short circuits like isinf(sdmove) && break, because they don’t suffer from the same need for explicit parentheses)

10 Likes