Closed oxinabox closed 9 years ago
How are you using nan
in your code?
I'm not sure that this will help you, but I use it when creating a lightweight version of one of my composite types. (to save on network transmission, in my parallel code). I want to set one of the fields to NaN so that if it is ever accesses (which on the lightweight version it shouldn't be), it becomes immediately apparent. I further have a version of the lightweight type that support converting, as part of me using it with ForwardDiff.jl
Yes there are other ways to do it, eg Nullable, which may be better. But because I was using NaN as a quick hack, I came across the aforementioned unexpected behavior.
EDIT: I've removed the code I posted cos that code is full of bugs and typos (clearly I need to sleep). Point being it doesn't seem logical that nan(Dual{Float32}) should produce a Float32. If it has to for implementation reasons, then that should be documented (if it isn't already)
It was added in commit https://github.com/JuliaDiff/DualNumbers.jl/commit/336b003af020e44e30064e9f1061f1a3b7de1a81 , if that helps you remember why you made it that way. I'm sure you had a good reason at the time.
Since we overload the comparison operators, I think it's safe to make this change. Will need some testing though.
Now, inf(T)
and nan(T)
are deprecated in favor of convert(T, Inf)
and convert(T, NaN)
, so I think these should simply be removed (after ample deprecation).
Resolved by #27
But a Dual NaN does exist, kinda:
The definition of nan(f)
There are two options for what could be done.
Either
nan{Dual{T}}
should a NaN in the real part and zero in the du part -- it makes sense to match the behavior of convert, and for the nan operator to apply to the real part.Or it should do as
nan(Complex{Float32})
does and throw an error:My code assumes that
nan{T<:Number}
gives me a NaN of type T. Or at very least makes it clear that it can't be done.