JuliaDiff / DualNumbers.jl

Julia package for representing dual numbers and for performing dual algebra
Other
80 stars 30 forks source link

Sqrt at 0.0 #12

Closed IainNZ closed 10 years ago

IainNZ commented 10 years ago
julia> sqrt(Dual(0.0))
dual(0.0,NaN)

So this surprised me... whats the intution behind it?

mlubin commented 10 years ago

This works,

julia> sqrt(Dual(0.0,1.0))
dual(0.0,Inf)

For Dual(0.0), it's computing 0.0*Inf which gives NaN. Should it be something else?

IainNZ commented 10 years ago

I'm not sure... I had something where I was changing the (x,y) coordinates of things and minimizing the Euclidean distance of points, but I didn't bother excluding the case where i=j, which is what gave me the Dual(0.0) to start with, e.g. I had what basically turned into sqrt(Dual(0.0) + Dual(0.0)). In that case, at least, it should be 0.0, I guess. I'm more generally surprised Julia defines 0.0 * Inf as NaN, I thought it would be 0.0

mlubin commented 10 years ago

Pretty sure that 0.0*Inf==NaN is a standard floating point rule. Okay to close this?

IainNZ commented 10 years ago

Oh yeah it seems standard. If someone ever files an issue about strange NaNs though, this should be first place to look.