I have encountered an unexpected (for myself) behavior of the ifelse() function. I thought that it would be easier to read if I used ifelse() function instead of an if-block. To see the problem that I had consider the following function and its call:
function foo(x, α)
ret = ifelse(x < α, log(x), log(-x))
return ret
end
foo(1.1, 2.0)
The call of this function returns a domain error as it tries to evaluate log(-1.1) which would not be the case if I used a regular if-block. Is it an intended behavior of the ifelse() function? I would prefer to use this function for readability purposes but it is not useful for such instances.