From 1fac08e708846a8f0ba0def60cd046ccbfeb425e Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Mon, 16 Jun 2025 15:31:25 -0700 Subject: [PATCH] Update double-conversion to 7630f84a10f9428b041d0471e71a562141e9684b. Change-Id: I37d176a938798cb74eae0a3a445182beb55a117d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434900 Commit-Queue: Ryan Macnak Reviewed-by: Alexander Aprelev --- PRESUBMIT.py | 3 ++- third_party/double-conversion/README.dart | 2 +- third_party/double-conversion/README.md | 20 ++++++++++++++++++- .../double-conversion/src/double-to-string.cc | 3 ++- .../double-conversion/src/double-to-string.h | 13 ++++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index d289ab26f9c..30eaaca5bcf 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -340,7 +340,8 @@ def _CheckClangFormat(input_api, output_api): f.ChangedContents())): is_deps = True break - if is_cpp_file(path) and os.path.isfile(path): + if is_cpp_file(path) and os.path.isfile( + path) and not path.startswith('third_party/'): files.append(path) if is_deps: diff --git a/third_party/double-conversion/README.dart b/third_party/double-conversion/README.dart index dd49b341b93..461b5414868 100644 --- a/third_party/double-conversion/README.dart +++ b/third_party/double-conversion/README.dart @@ -1,5 +1,5 @@ URL: https://github.com/google/double-conversion -Version: 032fa6a7d2c319b20d3928f5d762648fa4029acf +Version: 7630f84a10f9428b041d0471e71a562141e9684b License: BSD License File: LICENSE diff --git a/third_party/double-conversion/README.md b/third_party/double-conversion/README.md index d8e9190c940..db5386ce104 100644 --- a/third_party/double-conversion/README.md +++ b/third_party/double-conversion/README.md @@ -19,7 +19,7 @@ There is extensive documentation in `double-conversion/string-to-double.h` and Building ======== -This library can be built with [scons][0] or [cmake][1]. +This library can be built with [scons][0], [cmake][1] or [bazel][2]. The checked-in Makefile simply forwards to scons, and provides a shortcut to run all tests: @@ -55,5 +55,23 @@ Use `-DBUILD_TESTING=ON` to build the test executable. make test/cctest/cctest +Bazel +--- + +The simplest way to adopt this library is through the [Bazel Central Registry](https://registry.bazel.build/modules/double-conversion). + +To build the library from the latest repository, run: + +``` +bazel build //:double-conversion +``` + +To run the unit test, run: + +``` +bazel test //:cctest +``` + [0]: http://www.scons.org/ [1]: https://cmake.org/ +[2]: https://bazel.build/ diff --git a/third_party/double-conversion/src/double-to-string.cc b/third_party/double-conversion/src/double-to-string.cc index 215eaa96d47..9ea3d18d5f7 100644 --- a/third_party/double-conversion/src/double-to-string.cc +++ b/third_party/double-conversion/src/double-to-string.cc @@ -180,7 +180,7 @@ bool DoubleToStringConverter::ToShortestIeeeNumber( return HandleSpecialValues(value, result_builder); } - int decimal_point; + int decimal_point = 0; bool sign; const int kDecimalRepCapacity = kBase10MaximalLength + 1; char decimal_rep[kDecimalRepCapacity]; @@ -405,6 +405,7 @@ void DoubleToStringConverter::DoubleToAscii(double v, if (mode == PRECISION && requested_digits == 0) { vector[0] = '\0'; *length = 0; + *point = 0; return; } diff --git a/third_party/double-conversion/src/double-to-string.h b/third_party/double-conversion/src/double-to-string.h index abe60e8810e..35449feeb7c 100644 --- a/third_party/double-conversion/src/double-to-string.h +++ b/third_party/double-conversion/src/double-to-string.h @@ -237,11 +237,24 @@ class DoubleToStringConverter { // kBase10MaximalLength significant digits). // "-1.7976931348623157e+308", "-1.7976931348623157E308" // In addition, the buffer must be able to hold the trailing '\0' character. + // + // Since the algorithm finds the shortest number of significant digits, it + // can produce an output that isn't the shortest possible if the + // decimal_in_shortest_high is high enough. For example, the number + // 1e23 could be written as 99999999999999991611392 with 23 + // digits, however, it only needs one significant digit 1, and thus the + // result is 100000000000000000000000, which has 24 digits. bool ToShortest(double value, StringBuilder* result_builder) const { return ToShortestIeeeNumber(value, result_builder, SHORTEST); } // Same as ToShortest, but for single-precision floats. + // + // Since the algorithm finds the shortest number of significant digits, it + // can, in very rare cases, produce an output that isn't the shortest possible. + // For example, the number 1e11f could be written as 99999997952 with 11 + // digits, however, it only needs one significant digit 1, and thus the + // result is 100000000000, which has 12 digits. bool ToShortestSingle(float value, StringBuilder* result_builder) const { return ToShortestIeeeNumber(value, result_builder, SHORTEST_SINGLE); }