Commit 5f28d4a6 authored by Vitaly Buka's avatar Vitaly Buka Committed by Commit Bot

Update double_conversion to 9df6272fefd846401afbf839cbe7d0f9e319fe08

9df6272 Move buffer and buffer_pos down (#125)
43c6826 Fix strtod.cc undefined constants (#123)
1dce44c Add full license to test .cc files missing it. (#121)
8857767 Add wasm32 as supported platform (#120)
a54561b Pseiderer/add nios2 and xtensa 001 (#119)
5cc233e Add support for microblaze.
4a51e73 Add support for e2k architecture. (#118)
7da5db9 Add min exponent width option in double-to-string conversion (#116)

Bug: 977230
Change-Id: I89fbe9295172df16ae2668b750aeac6293e7b361
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2023865Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735656}
parent 9c31a213
......@@ -2,8 +2,8 @@ Name: Google Double Conversion
Short Name: double-conversion
URL: https://github.com/google/double-conversion
Version: 0
Date: 2019-06-22
Revision: 3f9cd30e1bca91c0a036ad8b2b7eb8e2d2290dd2
Date: 2020-01-27
Revision: 9df6272fefd846401afbf839cbe7d0f9e319fe08
License: BSD
License File: LICENSE
Security Critical: yes
......
......@@ -97,6 +97,7 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
return;
}
DOUBLE_CONVERSION_ASSERT(exponent < 1e4);
// Changing this constant requires updating the comment of DoubleToStringConverter constructor
const int kMaxExponentLength = 5;
char buffer[kMaxExponentLength + 1];
buffer[kMaxExponentLength] = '\0';
......@@ -105,6 +106,11 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
buffer[--first_char_pos] = '0' + (exponent % 10);
exponent /= 10;
}
// Add prefix '0' to make exponent width >= min(min_exponent_with_, kMaxExponentLength)
// For example: convert 1e+9 -> 1e+09, if min_exponent_with_ is set to 2
while(kMaxExponentLength - first_char_pos < std::min(min_exponent_width_, kMaxExponentLength)) {
buffer[--first_char_pos] = '0';
}
result_builder->AddSubstring(&buffer[first_char_pos],
kMaxExponentLength - first_char_pos);
}
......
......@@ -104,6 +104,12 @@ class DoubleToStringConverter {
// ToPrecision(230.0, 2) -> "230"
// ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT.
// ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT.
//
// 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.
// The min_exponent_width is clamped to 5.
// As such, the exponent may never have more than 5 digits in total.
DoubleToStringConverter(int flags,
const char* infinity_symbol,
const char* nan_symbol,
......@@ -111,7 +117,8 @@ class DoubleToStringConverter {
int decimal_in_shortest_low,
int decimal_in_shortest_high,
int max_leading_padding_zeroes_in_precision_mode,
int max_trailing_padding_zeroes_in_precision_mode)
int max_trailing_padding_zeroes_in_precision_mode,
int min_exponent_width = 0)
: flags_(flags),
infinity_symbol_(infinity_symbol),
nan_symbol_(nan_symbol),
......@@ -121,7 +128,8 @@ class DoubleToStringConverter {
max_leading_padding_zeroes_in_precision_mode_(
max_leading_padding_zeroes_in_precision_mode),
max_trailing_padding_zeroes_in_precision_mode_(
max_trailing_padding_zeroes_in_precision_mode) {
max_trailing_padding_zeroes_in_precision_mode),
min_exponent_width_(min_exponent_width) {
// When 'trailing zero after the point' is set, then 'trailing point'
// must be set too.
DOUBLE_CONVERSION_ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) ||
......@@ -378,6 +386,7 @@ class DoubleToStringConverter {
const int decimal_in_shortest_high_;
const int max_leading_padding_zeroes_in_precision_mode_;
const int max_trailing_padding_zeroes_in_precision_mode_;
const int min_exponent_width_;
DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS(DoubleToStringConverter);
};
......
......@@ -441,11 +441,6 @@ double StringToDoubleConverter::StringToIeee(
}
}
// The longest form of simplified number is: "-<significant digits>.1eXXX\0".
const int kBufferSize = kMaxSignificantDigits + 10;
char buffer[kBufferSize]; // NOLINT: size is known at compile time.
int buffer_pos = 0;
// Exponent will be adjusted if insignificant digits of the integer part
// or insignificant leading zeros of the fractional part are dropped.
int exponent = 0;
......@@ -480,7 +475,6 @@ double StringToDoubleConverter::StringToIeee(
return junk_string_value_;
}
DOUBLE_CONVERSION_ASSERT(buffer_pos == 0);
*processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::Infinity() : Double::Infinity();
}
......@@ -499,7 +493,6 @@ double StringToDoubleConverter::StringToIeee(
return junk_string_value_;
}
DOUBLE_CONVERSION_ASSERT(buffer_pos == 0);
*processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::NaN() : Double::NaN();
}
......@@ -556,6 +549,12 @@ double StringToDoubleConverter::StringToIeee(
bool octal = leading_zero && (flags_ & ALLOW_OCTALS) != 0;
// The longest form of simplified number is: "-<significant digits>.1eXXX\0".
const int kBufferSize = kMaxSignificantDigits + 10;
DOUBLE_CONVERSION_STACK_UNINITIALIZED char
buffer[kBufferSize]; // NOLINT: size is known at compile time.
int buffer_pos = 0;
// Copy significant digits of the integer part (if any) to the buffer.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
......
......@@ -35,10 +35,12 @@
namespace double_conversion {
#if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
// 2^53 = 9007199254740992.
// Any integer with at most 15 decimal digits will hence fit into a double
// (which has a 53bit significand) without loss of precision.
static const int kMaxExactDoubleIntegerDecimalDigits = 15;
#endif // #if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
// 2^64 = 18446744073709551616 > 10^19
static const int kMaxUint64DecimalDigits = 19;
......@@ -55,6 +57,7 @@ static const int kMinDecimalPower = -324;
static const uint64_t kMaxUint64 = DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF);
#if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
static const double exact_powers_of_ten[] = {
1.0, // 10^0
10.0,
......@@ -82,6 +85,7 @@ static const double exact_powers_of_ten[] = {
10000000000000000000000.0
};
static const int kExactPowersOfTenSize = DOUBLE_CONVERSION_ARRAY_SIZE(exact_powers_of_ten);
#endif // #if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
// Maximum number of significant digits in the decimal representation.
// In fact the value is 772 (see conversions.cc), but to give us some margin
......
......@@ -64,6 +64,12 @@ inline void abort_noreturn() { abort(); }
#endif
#endif
#if defined(__clang__) && __has_attribute(uninitialized)
#define DOUBLE_CONVERSION_STACK_UNINITIALIZED __attribute__((uninitialized))
#else
#define DOUBLE_CONVERSION_STACK_UNINITIALIZED
#endif
// Double operations detection based on target architecture.
// Linux uses a 80bit wide floating point stack on x86. This induces double
// rounding, which in turn leads to wrong results.
......@@ -94,15 +100,17 @@ int main(int argc, char** argv) {
defined(__ARMEL__) || defined(__avr32__) || defined(_M_ARM) || defined(_M_ARM64) || \
defined(__hppa__) || defined(__ia64__) || \
defined(__mips__) || \
defined(__nios2__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
defined(__SH4__) || defined(__alpha__) || \
defined(_MIPS_ARCH_MIPS32R2) || defined(__ARMEB__) ||\
defined(__AARCH64EL__) || defined(__aarch64__) || defined(__AARCH64EB__) || \
defined(__riscv) || \
defined(__riscv) || defined(__e2k__) || \
defined(__or1k__) || defined(__arc__) || \
defined(__EMSCRIPTEN__)
defined(__microblaze__) || defined(__XTENSA__) || \
defined(__EMSCRIPTEN__) || defined(__wasm32__)
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#elif defined(__mc68000__) || \
defined(__pnacl__) || defined(__native_client__)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment