Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't convert to Float64 in Printf #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jmkuhn
Copy link
Contributor

@jmkuhn jmkuhn commented Feb 22, 2024

Fixes #178

@@ -807,6 +807,8 @@ promote_rule(::Type{Irrational{s}}, T::Type{Complex{F}}) where {s,F<:DecimalFloa
Base.widen(::Type{Dec32}) = Dec64
Base.widen(::Type{Dec64}) = Dec128

Printf.tofloat(x::DecimalFloatingPoint) = BigFloat(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to pass a precision? Otherwise the BigFloat constructor may use too low a precision.

Why do we need a conversion at all here? Wouldn't it be possible to have Printf.tofloat(x::DecimalFloatingPoint) = x and support printing natively on decimal floating point values? It seems like a shame to do a lossy conversion to binary floating point for printing — kinda defeats the point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also prefer to not go through BigFloat. In the original Printf PR, there is another interface mentioned where we could pass a buffer of digit chars and the location of the decimal point and have that formatted.
I would like to try that interface but I can't find it in the current code. JuliaLang/julia#32859 (comment) Is that interface implemented @quinnj ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

printf is converting to Float64
2 participants