Skip to content

Displaying integer-valued real numbers #6

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

Closed
1 of 4 tasks
mbillingr opened this issue Sep 28, 2020 · 3 comments
Closed
1 of 4 tasks

Displaying integer-valued real numbers #6

mbillingr opened this issue Sep 28, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@mbillingr
Copy link
Owner

mbillingr commented Sep 28, 2020

The interpreter prints real numbers like integers if their fractional part is zero.
Example:

>> 1.0
1

With small numbers this is no big deal but it may cause confusion if the fractional part is lost due to the limited precision of the floating point representation.

>> (define a 1234567890.12)
>> (* a a)
1524157875315348200

1524157875315348200 looks like an integer, when in fact it is a floating point number with limited precision. Printing the number as 1524157875315348200.0 would communicate that fact more clearly.
Thank you @pgl10 for reporting!

I can see several options to fix this:

  • (easy) Use the debug formatter, which prints floats with .0 at the end but never uses scientific notation (Example).
  • (easy) Wait for the {:g?} format switch which may never come.
  • (moderate) Implement custom formatting to properly show the available precision.
  • (trivial) Leave as it is, arguing that the user should not be concerned with the internal implementation of numbers. This argument breaks down for large numbers.

At the moment, I prefer the first option. The trailing zeros are a bit ugly for large numbers but it's so easy to implement.

Any thoughts?

@mbillingr mbillingr added the bug Something isn't working label Sep 28, 2020
@pgl10
Copy link

pgl10 commented Sep 28, 2020

It is not so easy to display always a real number as a real. Sometimes it looks like an integer. I know a way to display always a real number as a real in C++ and I let you know about this, but I don't know Rust.

@mbillingr
Copy link
Owner Author

I think there is an easy way in Rust to it. Otherwise I'll try to adopt your C++ solution.

@mbillingr
Copy link
Owner Author

Implemented in f2a781f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants