-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
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.
@swift-ci Please smoke test |
stdlib/public/runtime/SwiftDtoa.cpp
Outdated
// 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) { |
There was a problem hiding this comment.
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"
@swift-ci Please test. |
Build failed |
Build failed |
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please smoke test |
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 thischange, 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.