ApproxFun.jl icon indicating copy to clipboard operation
ApproxFun.jl copied to clipboard

Strange behaviour for piecewise functions

Open carlocab opened this issue 4 years ago • 1 comments

Creating piecewise-defined functions silently gives you the wrong result. For example:

using ApproxFun

f(z) = z < 1/2 ? 4z : 4 * (1 - z)
d = Interval(0.0, 1.0)
x = Fun(d)
g = f(x)

Then, evaluating g(0.25) gives you the wrong answer of 3.0.

Changing the definition of f to use min instead of the ternary operator seems to fix it, but it would've been nice to get a warning, at least.

carlocab avatar Jun 04 '20 20:06 carlocab

Ahhh, it's because < returns true or false. I agree it should probably throw an error

dlfivefifty avatar Jun 04 '20 22:06 dlfivefifty