-
Notifications
You must be signed in to change notification settings - Fork 134
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
format: ~Nf gives surprising result for floats with negative exponents. #2771
Comments
Great catch, thank you a lot for reporting this! Also for positive exponents: ?- format("~3f", [1.0e234]). 1.0e2 true. I think some way to reason a bit more about floats is needed (related: #1343). For example, we can do: ?- X is float_integer_part(1.0e234). X = 1.0e234. But how do we even get at the integer here so that we can format it? |
First, #2772 must be resolved which effectively gives the digits in front of the dot. |
This addresses mthom#2771, using a new internal predicate resorting to to_string(). Many thanks to Trevor Merrifield for reporting this issue! There is still room for improvements: With better support for inspecting floats, more of this logic can be moved to Prolog; also, there may be a way to obtain the float with greater precision, and with fewer needed Rust primitives.
Could you please take a look at triska@d9a7305 and see if it solves your issue? With this patch, I get: ?- format("~3f", [1.0e-6]). 0.000 true. |
Yes, it works for the failing case! I tested the patch on top of master.
I don't have the background to comment on the relationship to #2772 . |
This patch is incompatible with the existing implementations that are based on double precision IEEE floats in base 2 and whose integers are not bounded. Namely: B, Ciao, ECLiPSe, SICStus, SWI, Trealla and who all are fine with #2772.
Why? The integers above 2^53 < 9.007e15 cannot all be represented exactly with floats. And the only thing one can thus do is to print out the exact value. Only floats with base 10 could represent that value exactly, which so far not a single Prolog system supports. The standard does permit this in 7.1.3. Note that the digits before the dot have to be the same as the result of:
In addition to above systems, IF, IV, and YAP produce the same result. |
Just to be sure: there are at least two separate cases to distinguish: |
I have one elementary question about this: Why must these horrific considerations be made at all: I interpret what Rust's |
IEEE floats came out 1985. The first paper to accurately print them decimally was 1990. Paper, not downloadable program. |
Expected result is
0.000
.The text was updated successfully, but these errors were encountered: