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

Add string(float, base = 16), string(float, base = 2) for %a formatting of floats #57281

Open
tgross35 opened this issue Feb 6, 2025 · 3 comments
Labels
display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests

Comments

@tgross35
Copy link

tgross35 commented Feb 6, 2025

It is currently possible to print floats (including BigFloat) using @printf "%a" x, but this seems to be the only way. Would it be feasible to add a form of this that goes through print/string? For example:

> string(Float16(1.6875), hex = true)
0x1.bp+0

This makes it more consistent with other numeric formatting that can be set with string(x, base = 16) or similar.

@Seelengrab
Copy link
Contributor

I'm not sure adding this is worth the complexity. There's a great package, About.jl, that supports these kinds of introspective queries very well.

@nsajko nsajko added feature Indicates new feature / enhancement requests display and printing Aesthetics and correctness of printed representations of objects. labels Feb 6, 2025
@tgross35
Copy link
Author

tgross35 commented Feb 11, 2025

Thanks for pointing at About.jl, I did not know about that and it looks quite nice. Base two was mostly a "nice to have" suggestion, it still seems like there should be a print-based version of hex formatting in Base that does not require printf.

(updated the issue)

@tgross35
Copy link
Author

Related note on bigfloat %a formatting #56941 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

3 participants