I’m curious as to why the results are different. Might anyone provide some insight into this?
To allay accusations of the XY problem, the context here is solving the unstable Bernoulli differential equation ẏ = by + y³, y(0) = 1, which has the closed-form solution
Your simplified example doesn’t show what you want but the real one ultimately is a question of floating point being able to represent both positive and negative zeroes, whereas integers can’t.
Using 1.0+0im causes both real and imaginary parts to be promoted to Float64, i.e. it is equivalent to 1.0+0.0im. Then, negating it flips the sign of both parts, because floating point numbers keep track of a sign bit for ±0.0.
In most calculations, the sign bit of zero doesn’t matter, but it causes sqrt to choose a different branch cut for the square root of negative real numbers:
Thank you for the article! I’ll take a look. I somehow forgot about negative zero in floats, and had I remembered, I’m not sure I’d have made the connection to what I was reading.