Skip to content

SR-3131: Adjust choice of decimal vs. exponential format #15805

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

Merged
merged 4 commits into from
Apr 12, 2018

Conversation

tbkka
Copy link
Contributor

@tbkka tbkka commented Apr 6, 2018

For each floating-point type, there is a range of integers which
can be exactly represented in that type. Adjust the formatting
logic so that we use decimal format for integers within this
range, exponential format for numbers outside of this range.

For example, Double has a 53-bit significand so can exactly
represent every integer from -(2^53)...(2^53). With this
change, we now use decimal format for these integers and
exponential format for values outside of this range. This is
a relatively small change from the previous logic -- we've
basically just moved the cutoff from 10^15 to 2^53 (≈ 10^17).

The decision for using exponential format for small numbers is
not changed.

This includes edits to the test suite to adapt to the change in
behavior.

Resolves #42728.

For each floating-point type, there is a range of integers which
can be exactly represented in that type.  Adjust the formatting
logic so that we use decimal format for integers within this
range, exponential format for numbers outside of this range.

For example, Double has a 53-bit significand so can exactly
represent every integer from `-(2^53)...(2^53)`.  With this
change, we now use decimal format for these integers and
exponential format for values outside of this range.  This is
a relatively small change from the previous logic -- we've
basically just moved the cutoff from 10^15 to 2^53 (about 10^17).

The decision for using exponential format for small numbers is
not changed.
@tbkka tbkka requested a review from stephentyrone April 6, 2018 21:42
@tbkka
Copy link
Contributor Author

tbkka commented Apr 6, 2018

@swift-ci Please smoke test

// as a cutoff for decimal vs. exponential format.
// The constant is written out in full here since it can't be
// expressed as a 64-bit integer.
if (decimalExponent < -3 || fabsl(d) > 18446744073709551616.0L) {
Copy link
Contributor

@stephentyrone stephentyrone Apr 6, 2018

Choose a reason for hiding this comment

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

Let's write this as 0x1.0p64L? It's a C++17-ism, but in practice I think it's widely supported by earlier clang and gcc.

instead of "18446744073709551616.0L"
@stephentyrone
Copy link
Contributor

@swift-ci Please test.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ec7f7b0

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ec7f7b0

@tbkka
Copy link
Contributor Author

tbkka commented Apr 11, 2018

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - ae7f7bb

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - ae7f7bb

@tbkka
Copy link
Contributor Author

tbkka commented Apr 12, 2018

@swift-ci Please smoke test

@tbkka tbkka merged commit 1cc1832 into swiftlang:master Apr 12, 2018
@tbkka tbkka deleted the tbkka-floating-point-SR-3131 branch April 12, 2018 16:36
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.

3 participants