Skip to content
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

Merged
merged 12 commits into from
Apr 1, 2018

Commits on Mar 23, 2018

  1. SR-106: New floating-point description implementation

    This 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.
    tbkka committed Mar 23, 2018
    Configuration menu
    Copy the full SHA
    116e0fe View commit details
    Browse the repository at this point in the history

Commits on Mar 26, 2018

  1. Configuration menu
    Copy the full SHA
    b3267bb View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    49ae1fa View commit details
    Browse the repository at this point in the history
  3. Separate extracting the integer part from clearing the integer part

    The previous code was unnecessarily obfuscated by the attempt to combine
    these two operations.
    tbkka committed Mar 26, 2018
    Configuration menu
    Copy the full SHA
    122051a View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    3cdb7d2 View commit details
    Browse the repository at this point in the history

Commits on Mar 29, 2018

  1. Configuration menu
    Copy the full SHA
    e12dd45 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8892d35 View commit details
    Browse the repository at this point in the history

Commits on Mar 30, 2018

  1. Configuration menu
    Copy the full SHA
    a3509c7 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'tbkka-floating-point-printing-C' of github.com:tbkka/sw…

    …ift into tbkka-floating-point-printing-C
    tbkka committed Mar 30, 2018
    Configuration menu
    Copy the full SHA
    849e31c View commit details
    Browse the repository at this point in the history
  3. 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.
    tbkka committed Mar 30, 2018
    Configuration menu
    Copy the full SHA
    6cd5c20 View commit details
    Browse the repository at this point in the history
  4. Rename SwiftDtoa to ".cpp"

    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.
    tbkka committed Mar 30, 2018
    Configuration menu
    Copy the full SHA
    4899bc1 View commit details
    Browse the repository at this point in the history

Commits on Apr 1, 2018

  1. Revert "Make the C++ exceptions here consistent"

    This reverts commit 6cd5c20.
    tbkka committed Apr 1, 2018
    Configuration menu
    Copy the full SHA
    bb27385 View commit details
    Browse the repository at this point in the history