New attempt at preserving the floating-point precision in uconvert#782
New attempt at preserving the floating-point precision in uconvert#782sostock merged 5 commits intoJuliaPhysics:masterfrom
uconvert#782Conversation
| F = floattype(T) | ||
| # Since conversion factors only have Float64 precision, | ||
| # there is no point in converting to BigFloat | ||
| convert(F == BigFloat ? Float64 : F, cf) |
There was a problem hiding this comment.
Perhaps using <: instead of == is safer to prevent possible BligFloat type changes.
| convert(F == BigFloat ? Float64 : F, cf) | |
| convert(F <: BigFloat ? Float64 : F, cf) |
What do you think @sostock?
There was a problem hiding this comment.
I think it is unlikely that BigFloat will be changed to a non-concrete type, but we can use <: if you prefer it.
There was a problem hiding this comment.
I think you're right. Perhaps just change== to === which is more common to compare types.
There was a problem hiding this comment.
I don’t really like using === on types, because the same type can have different representations (although it shouldn’t be a problem in this case because BigFloat is a concrete type):
julia> (Rational{T} where T) == (Rational{S} where S)
true
julia> (Rational{T} where T) === (Rational{S} where S)
false
I also didn’t find an instance of using === on types in this package, but there is one for ==: https://github.com/PainterQubits/Unitful.jl/blob/f375caf8f7c60f0dc2e284a97fc902365f55ab76/src/conversion.jl#L67
There was a problem hiding this comment.
I see, that makes perfect sense.
Closes #753.
This is a follow-up to #754. It should now work without breaking something.
@eliascarv I took the first commits from #754 and added the
floattypefunction.We should also look at our
promote_rulemethods to see whether we can use this to address #767.