-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
SR-106: New floating-point description
implementation
#15474
SR-106: New floating-point description
implementation
#15474
Commits on Mar 23, 2018
-
SR-106: New floating-point
description
implementationThis replaces the current implementation of `description` and `debugDescription` for the standard floating-point types with a new formatting routine based on a variation of Florian Loitsch' Grisu2 algorithm with changes suggested by Andrysco, Jhala, and Lerner's 2016 paper describing Errol3. Unlike the earlier code based on `sprintf` with a fixed number of digits, this version always chooses the optimal number of digits. As such, we can now use the exact same output for both `description` and `debugDescription` (except of course that `debugDescription` provides full detail for NaNs). The implementation has been extensively commented; people familiar with Grisu-style algorithms should find the code easy to understand. This implementation is: * Fast. It uses only fixed-width integer arithmetic and has constant memory and time requirements. * Simple. It is only a little more complex than Loitsch' original implementation of Grisu2. The digit decomposition logic for double is less than 300 lines of standard C (half of which is common arithmetic support routines). * Always Accurate. Converting the decimal form back to binary (using an accurate algorithm such as Clinger's) will always yield exactly the original binary value. For the IEEE 754 formats, the round-trip will produce exactly the same bit pattern in memory. This is an essential requirement for JSON serialization, debugging, and logging. * Always Short. This always selects an accurate result with the minimum number of decimal digits. (So that `1.0 / 10.0` will always print `0.1`.) * Always Close. Among all accurate, short results, this always chooses the result that is closest to the exact floating-point value. (In case of an exact tie, it rounds the last digit even.) This resolves SR-106 and related issues that have complained about the floating-point `description` properties being inexact.
Configuration menu - View commit details
-
Copy full SHA for 116e0fe - Browse repository at this point
Copy the full SHA 116e0feView commit details
Commits on Mar 26, 2018
-
Configuration menu - View commit details
-
Copy full SHA for b3267bb - Browse repository at this point
Copy the full SHA b3267bbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 49ae1fa - Browse repository at this point
Copy the full SHA 49ae1faView commit details -
Separate
extracting
the integer part fromclearing
the integer partThe previous code was unnecessarily obfuscated by the attempt to combine these two operations.
Configuration menu - View commit details
-
Copy full SHA for 122051a - Browse repository at this point
Copy the full SHA 122051aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3cdb7d2 - Browse repository at this point
Copy the full SHA 3cdb7d2View commit details
Commits on Mar 29, 2018
-
Configuration menu - View commit details
-
Copy full SHA for e12dd45 - Browse repository at this point
Copy the full SHA e12dd45View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8892d35 - Browse repository at this point
Copy the full SHA 8892d35View commit details
Commits on Mar 30, 2018
-
Configuration menu - View commit details
-
Copy full SHA for a3509c7 - Browse repository at this point
Copy the full SHA a3509c7View commit details -
Merge branch 'tbkka-floating-point-printing-C' of github.com:tbkka/sw…
…ift into tbkka-floating-point-printing-C
Configuration menu - View commit details
-
Copy full SHA for 849e31c - Browse repository at this point
Copy the full SHA 849e31cView commit details -
Make the C++ exceptions here consistent
Adding a C source file somehow exposed an issue in an unrelated C++ file. Thanks to Joe Groff for the fix.
Configuration menu - View commit details
-
Copy full SHA for 6cd5c20 - Browse repository at this point
Copy the full SHA 6cd5c20View commit details -
Having a C file in stdlib/public/runtime causes strange build failures on Linux in unrelated C++ files. As a workaround, rename SwiftDtoa.c to .cpp to see if that avoids the problems.
Configuration menu - View commit details
-
Copy full SHA for 4899bc1 - Browse repository at this point
Copy the full SHA 4899bc1View commit details
Commits on Apr 1, 2018
-
Revert "Make the C++ exceptions here consistent"
This reverts commit 6cd5c20.
Configuration menu - View commit details
-
Copy full SHA for bb27385 - Browse repository at this point
Copy the full SHA bb27385View commit details