-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
RFC: bit-float literal #9371
Comments
From previous interaction with hex floats and deficient compilers, I think the parser is using C |
That was what I feared: I guess the two alternatives would be: a. Use the "implicit macro" approach, similar to |
You could experiment with adding support for this in JuliaParser. This would go in the lexing code and should be pretty straightforward. Just eval the resulting AST to check for correctness. My feeling is that it would not be terribly hard to support this. |
I'm ok with adding this feature – largely because it doesn't erode the numeric literal juxtaposition syntax any further but also because it would probably be handy for seeing what's going on with floats, as simon said. So +1 |
Actually, using JuliaParser.jl doesn't actually require any changes at all, as it already gets passed to straight to |
Awesome idea. I've actually wished this existed a few times in rather odd circumstances: doing manual binary search of all things. Imagine evaluating f(0b1.1p0) and getting a bad result, then f(0b1.11p0) and getting a good result, and going on to check f(0b1.101p0) which is at the midpoint of the interval and so on. Not all that common scenario, but happens when you don't have code for recognizing the two results and decide to judge them by sight. BTW, would something break if the p0 could be omitted from 0b1.0p0 and 0x1.0p0? You can omit e0 from 1.0e0, and the added convenience is significant despite the difference being just two characters. |
Since this is a new feature that doesn't seem to be under active development, moving to 1.0. |
These should be implemented in string macros IMO. |
I would like to propose a bit-float literal:
As the name suggests, it's similar to a hex float literal, except just binary digits are used (conveniently, we can keep
p
as the exponent symbol, as it is base 2 in both cases).The purpose is somewhat distinct: whereas hex floats are mainly used as an interchange format to ensure no rounding error when converting to/from strings, bit float literals are more for human consumption, basically as a more understandable format than
bits
, to understand and explain what floats look like underneath (e.g. to answer questions like this).The two main changes required:
@printf
format: I was thinking%b
(as it comes after%a
), but other suggestions are welcome.Thoughts?
The text was updated successfully, but these errors were encountered: