Closed tomasaschan closed 10 years ago
I don't think it is possible to do this in a type stable way. The other consideration is that the unit computation should really be independent of whatever the underlying type does (and ideally happen in the type system), so I think the first version is better.
Yeah, you're probably right.
However, it sort of bugs me that it's shown as NaN kg
rather than NaN
- even if the calculations of units are done independently of value, maybe it's possible to show NaN
values differently? Basically, I'm suggesting changing show(::SIQuantity)
to
function show{T,m,kg,s,A,K,mol,cd}(io::IO,x::SIQuantity{T,m,kg,s,A,K,mol,cd})
show(io,x.val)
if !isnan(x.val)
print(io," ")
show(io,unit(x))
end
end
-1 – NaN
is just a floating-point value and special-casing how you show it seems confusing.
Oh well - I guess my opinion is just the odd one in this case. I'll have to live with it =)
Does it make sense to preserve unit information for
NaN
values?I would assume that
NaN
values "poison" any other numbers in calculations as usual, but it turns out I'm wrong - e.g. multiplication byNaN
does preserve units. Currently,I think it would make more sense if
Is this possible without violating type stability?