mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-22325 Update double-conversion to v3.3.0
This commit is contained in:
parent
bfbf578f1c
commit
acfe1c299b
10 changed files with 238 additions and 6 deletions
|
@ -94,7 +94,14 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
|
|||
StringBuilder* result_builder) const {
|
||||
DOUBLE_CONVERSION_ASSERT(length != 0);
|
||||
result_builder->AddCharacter(decimal_digits[0]);
|
||||
if (length != 1) {
|
||||
if (length == 1) {
|
||||
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL) != 0) {
|
||||
result_builder->AddCharacter('.');
|
||||
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL) != 0) {
|
||||
result_builder->AddCharacter('0');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result_builder->AddCharacter('.');
|
||||
result_builder->AddSubstring(&decimal_digits[1], length-1);
|
||||
}
|
||||
|
|
|
@ -93,7 +93,9 @@ class DoubleToStringConverter {
|
|||
EMIT_TRAILING_DECIMAL_POINT = 2,
|
||||
EMIT_TRAILING_ZERO_AFTER_POINT = 4,
|
||||
UNIQUE_ZERO = 8,
|
||||
NO_TRAILING_ZERO = 16
|
||||
NO_TRAILING_ZERO = 16,
|
||||
EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL = 32,
|
||||
EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL = 64
|
||||
};
|
||||
|
||||
// Flags should be a bit-or combination of the possible Flags-enum.
|
||||
|
@ -112,6 +114,13 @@ class DoubleToStringConverter {
|
|||
// of the result in precision mode. Matches printf's %g.
|
||||
// When EMIT_TRAILING_ZERO_AFTER_POINT is also given, one trailing zero is
|
||||
// preserved.
|
||||
// - EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL: when the input number has
|
||||
// exactly one significant digit and is converted into exponent form then a
|
||||
// trailing decimal point is appended to the significand in shortest mode
|
||||
// or in precision mode with one requested digit.
|
||||
// - EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL: in addition to a trailing
|
||||
// decimal point emits a trailing '0'-character. This flag requires the
|
||||
// EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL flag.
|
||||
//
|
||||
// Infinity symbol and nan_symbol provide the string representation for these
|
||||
// special values. If the string is nullptr and the special value is encountered
|
||||
|
@ -147,6 +156,22 @@ class DoubleToStringConverter {
|
|||
// ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
|
||||
// ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
|
||||
//
|
||||
// When converting numbers with exactly one significant digit to exponent
|
||||
// form in shortest mode or in precision mode with one requested digit, the
|
||||
// EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT flags have
|
||||
// no effect. Use the EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL flag to
|
||||
// append a decimal point in this case and the
|
||||
// EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL flag to also append a
|
||||
// '0'-character in this case.
|
||||
// Example with decimal_in_shortest_low = 0:
|
||||
// ToShortest(0.0009) -> "9e-4"
|
||||
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL deactivated.
|
||||
// ToShortest(0.0009) -> "9.e-4"
|
||||
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL activated.
|
||||
// ToShortest(0.0009) -> "9.0e-4"
|
||||
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL activated and
|
||||
// EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL activated.
|
||||
//
|
||||
// The min_exponent_width is used for exponential representations.
|
||||
// The converter adds leading '0's to the exponent until the exponent
|
||||
// is at least min_exponent_width digits long.
|
||||
|
|
71
vendor/double-conversion/upstream/.github/workflows/ci.yml
vendored
Normal file
71
vendor/double-conversion/upstream/.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
name: ci
|
||||
|
||||
on: push
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
container: [ ubuntu-latest, macos-latest, windows-latest ]
|
||||
build_type: [ Debug, Release ]
|
||||
|
||||
|
||||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
|
||||
# You can convert this to a matrix build if you need cross-platform coverage.
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
||||
runs-on: ${{ matrix.container }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Configure
|
||||
shell: bash
|
||||
# Configure CMake in a 'buildX' subdirectory.
|
||||
# We can't use `build` as `BUILD` is already taken by the bazel build file.
|
||||
# On Mac and Windows this leads to a conflict.
|
||||
run: |
|
||||
mkdir -p buildX
|
||||
cd buildX
|
||||
cmake -DBUILD_TESTING=ON \
|
||||
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=${{ github.workspace }}/install_dir \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
..
|
||||
|
||||
- name: Build shared
|
||||
run: |
|
||||
cmake --build buildX --config ${{ matrix.build_type }}
|
||||
|
||||
- name: Install shared
|
||||
run: |
|
||||
cmake --install buildX --config ${{ matrix.build_type }}
|
||||
|
||||
- name: Build static
|
||||
run: |
|
||||
cmake -DBUILD_SHARED_LIBS=OFF buildX
|
||||
cmake --build buildX --config ${{ matrix.build_type }}
|
||||
|
||||
- name: Install static
|
||||
run: |
|
||||
cmake --install buildX --config ${{ matrix.build_type }}
|
||||
|
||||
- name: Test
|
||||
if: runner.os != 'Windows'
|
||||
working-directory: ${{ github.workspace }}/buildX
|
||||
# Execute all tests.
|
||||
run: |
|
||||
ctest
|
||||
# Also run the tests directly, just in case we forgot to add it to ctest.
|
||||
test/cctest/cctest
|
||||
|
||||
- name: Test - Windows
|
||||
if: runner.os == 'Windows'
|
||||
working-directory: ${{ github.workspace }}/buildX
|
||||
# Execute all tests.
|
||||
run: |
|
||||
ctest -C ${{ matrix.build_type }}
|
||||
# Also run the tests directly, just in case we forgot to add it to ctest.
|
||||
test/cctest/${{ matrix.build_type }}/cctest.exe
|
26
vendor/double-conversion/upstream/.github/workflows/scons.yml
vendored
Normal file
26
vendor/double-conversion/upstream/.github/workflows/scons.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
name: scons
|
||||
|
||||
on: push
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install scons
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
make
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
make test
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(double-conversion VERSION 3.2.0)
|
||||
project(double-conversion VERSION 3.3.0)
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
|
||||
|
||||
|
|
19
vendor/double-conversion/upstream/Changelog
vendored
19
vendor/double-conversion/upstream/Changelog
vendored
|
@ -1,3 +1,22 @@
|
|||
2023-05-18:
|
||||
Add flags to control trailing decimal and zero in exponent
|
||||
form when input has one significant digit.
|
||||
|
||||
Update changelog and version number.
|
||||
|
||||
2022-09-01:
|
||||
Fix some compile warnings in Visual Studio.
|
||||
|
||||
2022-07-07:
|
||||
Fixed all -Wzero-as-null-pointer-constant warnings.
|
||||
|
||||
2022-06-25:
|
||||
Add a cast to silence a signedness conversion warning.
|
||||
|
||||
2022-01-30:
|
||||
Fix warnings on Windows.
|
||||
Give shared-lib option.
|
||||
|
||||
2022-01-16:
|
||||
Install Visual Studio debugger (pdb) files.
|
||||
|
||||
|
|
2
vendor/double-conversion/upstream/SConstruct
vendored
2
vendor/double-conversion/upstream/SConstruct
vendored
|
@ -16,7 +16,7 @@ optimize = ARGUMENTS.get('optimize', 0)
|
|||
env.Replace(CXX = ARGUMENTS.get('CXX', 'g++'))
|
||||
|
||||
# for shared lib, requires scons 2.3.0
|
||||
env['SHLIBVERSION'] = '3.0.0'
|
||||
env['SHLIBVERSION'] = '3.2.0'
|
||||
|
||||
CCFLAGS = []
|
||||
if int(debug):
|
||||
|
|
|
@ -79,7 +79,14 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
|
|||
StringBuilder* result_builder) const {
|
||||
DOUBLE_CONVERSION_ASSERT(length != 0);
|
||||
result_builder->AddCharacter(decimal_digits[0]);
|
||||
if (length != 1) {
|
||||
if (length == 1) {
|
||||
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL) != 0) {
|
||||
result_builder->AddCharacter('.');
|
||||
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL) != 0) {
|
||||
result_builder->AddCharacter('0');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result_builder->AddCharacter('.');
|
||||
result_builder->AddSubstring(&decimal_digits[1], length-1);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,9 @@ class DoubleToStringConverter {
|
|||
EMIT_TRAILING_DECIMAL_POINT = 2,
|
||||
EMIT_TRAILING_ZERO_AFTER_POINT = 4,
|
||||
UNIQUE_ZERO = 8,
|
||||
NO_TRAILING_ZERO = 16
|
||||
NO_TRAILING_ZERO = 16,
|
||||
EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL = 32,
|
||||
EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL = 64
|
||||
};
|
||||
|
||||
// Flags should be a bit-or combination of the possible Flags-enum.
|
||||
|
@ -97,6 +99,13 @@ class DoubleToStringConverter {
|
|||
// of the result in precision mode. Matches printf's %g.
|
||||
// When EMIT_TRAILING_ZERO_AFTER_POINT is also given, one trailing zero is
|
||||
// preserved.
|
||||
// - EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL: when the input number has
|
||||
// exactly one significant digit and is converted into exponent form then a
|
||||
// trailing decimal point is appended to the significand in shortest mode
|
||||
// or in precision mode with one requested digit.
|
||||
// - EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL: in addition to a trailing
|
||||
// decimal point emits a trailing '0'-character. This flag requires the
|
||||
// EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL flag.
|
||||
//
|
||||
// Infinity symbol and nan_symbol provide the string representation for these
|
||||
// special values. If the string is NULL and the special value is encountered
|
||||
|
@ -132,6 +141,22 @@ class DoubleToStringConverter {
|
|||
// ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
|
||||
// ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
|
||||
//
|
||||
// When converting numbers with exactly one significant digit to exponent
|
||||
// form in shortest mode or in precision mode with one requested digit, the
|
||||
// EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT flags have
|
||||
// no effect. Use the EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL flag to
|
||||
// append a decimal point in this case and the
|
||||
// EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL flag to also append a
|
||||
// '0'-character in this case.
|
||||
// Example with decimal_in_shortest_low = 0:
|
||||
// ToShortest(0.0009) -> "9e-4"
|
||||
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL deactivated.
|
||||
// ToShortest(0.0009) -> "9.e-4"
|
||||
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL activated.
|
||||
// ToShortest(0.0009) -> "9.0e-4"
|
||||
// with EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL activated and
|
||||
// EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL activated.
|
||||
//
|
||||
// The min_exponent_width is used for exponential representations.
|
||||
// The converter adds leading '0's to the exponent until the exponent
|
||||
// is at least min_exponent_width digits long.
|
||||
|
|
|
@ -278,6 +278,32 @@ TEST(DoubleToShortest) {
|
|||
builder.Reset();
|
||||
CHECK(dc6.ToShortest(-Double::NaN(), &builder));
|
||||
CHECK_EQ("NaN", builder.Finalize());
|
||||
|
||||
// Test examples with one significant digit.
|
||||
flags = DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT;
|
||||
DoubleToStringConverter dc7(flags, NULL, NULL, 'e', 0, 0, 0, 0);
|
||||
flags = DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL;
|
||||
DoubleToStringConverter dc8(flags, NULL, NULL, 'e', 0, 0, 0, 0);
|
||||
flags = DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL;
|
||||
DoubleToStringConverter dc9(flags, NULL, NULL, 'e', 0, 0, 0, 0);
|
||||
|
||||
builder.Reset();
|
||||
CHECK(dc7.ToShortest(0.0009, &builder));
|
||||
CHECK_EQ("9e-4", builder.Finalize());
|
||||
|
||||
builder.Reset();
|
||||
CHECK(dc8.ToShortest(0.0009, &builder));
|
||||
CHECK_EQ("9.e-4", builder.Finalize());
|
||||
|
||||
builder.Reset();
|
||||
CHECK(dc9.ToShortest(0.0009, &builder));
|
||||
CHECK_EQ("9.0e-4", builder.Finalize());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1259,6 +1285,32 @@ TEST(DoubleToPrecision) {
|
|||
builder.Reset();
|
||||
CHECK(dc5.ToPrecision(2000080, 5, &builder));
|
||||
CHECK_EQ("2.0001e6", builder.Finalize());
|
||||
|
||||
// Test examples with one significant digit.
|
||||
flags = DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT;
|
||||
DoubleToStringConverter dc12(flags, NULL, NULL, 'e', 0, 0, 0, 0);
|
||||
flags = DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL;
|
||||
DoubleToStringConverter dc13(flags, NULL, NULL, 'e', 0, 0, 0, 0);
|
||||
flags = DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT |
|
||||
DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL |
|
||||
DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL;
|
||||
DoubleToStringConverter dc14(flags, NULL, NULL, 'e', 0, 0, 0, 0);
|
||||
|
||||
builder.Reset();
|
||||
CHECK(dc12.ToPrecision(0.0009, 1, &builder));
|
||||
CHECK_EQ("9e-4", builder.Finalize());
|
||||
|
||||
builder.Reset();
|
||||
CHECK(dc13.ToPrecision(0.0009, 1, &builder));
|
||||
CHECK_EQ("9.e-4", builder.Finalize());
|
||||
|
||||
builder.Reset();
|
||||
CHECK(dc14.ToPrecision(0.0009, 1, &builder));
|
||||
CHECK_EQ("9.0e-4", builder.Finalize());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue