Bug 1686831 - Update double-conversion to upstream revision bf46072. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D103134
This commit is contained in:
Mike Hommey 2021-01-29 04:25:27 +00:00
Родитель 63d408918e
Коммит cc35b21767
13 изменённых файлов: 267 добавлений и 166 удалений

Просмотреть файл

@ -1,30 +1,12 @@
commit 4a51e730d3604c01637a9ff9e00b051e5f4e9b93
Author: Florian Loitsch <florian@loitsch.com>
Date: Mon Sep 2 18:06:17 2019 +0200
commit bf4607277fa7133825cb7899015374917cd06b8f
Author: Mike Hommey <mhommey@mozilla.com>
Date: Tue Jan 26 19:46:13 2021 +0900
Add support for e2k architecture. (#118)
diff --git a/Changelog b/Changelog
index 12b8a51..f774727 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,6 @@
+2019-09-02:
+ Add support for e2k architectur. Thanks to Michael Shigorin.
+
2019-08-01:
Add min exponent width option in double-to-string conversion.
diff --git a/double-conversion/utils.h b/double-conversion/utils.h
index a66289e..1a71df0 100644
--- a/double-conversion/utils.h
+++ b/double-conversion/utils.h
@@ -100,7 +100,7 @@ int main(int argc, char** argv) {
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__)
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
Add a flag to make precision mode like printf's %g (#149)
With this, %g can be emulated with:
```
DoubleToStringConverter cvt(
UNIQUE_ZERO | NO_TRAILING_ZERO | EMIT_POSITIVE_EXPONENT_SIGN,
"inf", "nan", 'e', 0, 0, 4, 0, 2)
```

Просмотреть файл

@ -1,7 +1,8 @@
diff --git a/mfbt/double-conversion/double-conversion/double-to-string.cc b/mfbt/double-conversion/double-conversion/double-to-string.cc
index 9255bce1713e9..1437e48bfd870 100644
--- a/mfbt/double-conversion/double-conversion/double-to-string.cc
+++ b/mfbt/double-conversion/double-conversion/double-to-string.cc
@@ -290,17 +290,19 @@ bool DoubleToStringConverter::ToExponent
@@ -290,17 +290,19 @@ bool DoubleToStringConverter::ToExponential(
exponent,
result_builder);
return true;
@ -21,8 +22,8 @@ diff --git a/mfbt/double-conversion/double-conversion/double-to-string.cc b/mfbt
return false;
}
@@ -332,16 +334,17 @@ bool DoubleToStringConverter::ToPrecisio
max_trailing_padding_zeroes_in_precision_mode_)) {
@@ -344,16 +346,17 @@ bool DoubleToStringConverter::ToPrecision(double value,
if (as_exponential) {
// Fill buffer to contain 'precision' digits.
// Usually the buffer is already at the correct length, but 'DoubleToAscii'
// is allowed to return less characters.
@ -40,15 +41,16 @@ diff --git a/mfbt/double-conversion/double-conversion/double-to-string.cc b/mfbt
(std::max)(0, precision - decimal_point),
result_builder);
diff --git a/mfbt/double-conversion/double-conversion/double-to-string.h b/mfbt/double-conversion/double-conversion/double-to-string.h
index 52d7986fe9048..a335f5c1ae55d 100644
--- a/mfbt/double-conversion/double-conversion/double-to-string.h
+++ b/mfbt/double-conversion/double-conversion/double-to-string.h
@@ -273,16 +273,17 @@ class DoubleToStringConverter {
// been provided to the constructor,
// - precision < kMinPericisionDigits
@@ -330,16 +330,17 @@ class DoubleToStringConverter {
// - precision > kMaxPrecisionDigits
// The last condition implies that the result will never contain more than
//
// The last condition implies that the result never contains more than
// kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
// exponent character, the exponent's sign, and at most 3 exponent digits).
// In addition, the buffer must be able to hold the trailing '\0' character.
MFBT_API bool ToPrecision(double value,
int precision,
+ bool* used_exponential_notation,

Просмотреть файл

@ -1,4 +1,5 @@
diff --git a/mfbt/double-conversion/double-conversion/double-to-string.h b/mfbt/double-conversion/double-conversion/double-to-string.h
index 6317a08a72aeb..52d7986fe9048 100644
--- a/mfbt/double-conversion/double-conversion/double-to-string.h
+++ b/mfbt/double-conversion/double-conversion/double-to-string.h
@@ -23,16 +23,17 @@
@ -19,84 +20,8 @@ diff --git a/mfbt/double-conversion/double-conversion/double-to-string.h b/mfbt/
public:
// When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
// or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
@@ -132,17 +133,17 @@ class DoubleToStringConverter {
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) ||
!((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
}
// Returns a converter following the EcmaScript specification.
- static const DoubleToStringConverter& EcmaScriptConverter();
+ static MFBT_API const DoubleToStringConverter& EcmaScriptConverter();
// Computes the shortest string of digits that correctly represent the input
// number. Depending on decimal_in_shortest_low and decimal_in_shortest_high
// (see constructor) it then either returns a decimal representation, or an
// exponential representation.
// Example with decimal_in_shortest_low = -6,
// decimal_in_shortest_high = 21,
// EMIT_POSITIVE_EXPONENT_SIGN activated, and
@@ -200,17 +201,17 @@ class DoubleToStringConverter {
// except for the following cases:
// - the input value is special and no infinity_symbol or nan_symbol has
// been provided to the constructor,
// - 'value' > 10^kMaxFixedDigitsBeforePoint, or
// - 'requested_digits' > kMaxFixedDigitsAfterPoint.
// The last two conditions imply that the result will never contain more than
// 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
// (one additional character for the sign, and one for the decimal point).
- bool ToFixed(double value,
+ MFBT_API bool ToFixed(double value,
int requested_digits,
StringBuilder* result_builder) const;
// Computes a representation in exponential format with requested_digits
// after the decimal point. The last emitted digit is rounded.
// If requested_digits equals -1, then the shortest exponential representation
// is computed.
//
@@ -232,17 +233,17 @@ class DoubleToStringConverter {
// except for the following cases:
// - the input value is special and no infinity_symbol or nan_symbol has
// been provided to the constructor,
// - 'requested_digits' > kMaxExponentialDigits.
// The last condition implies that the result will never contain more than
// kMaxExponentialDigits + 8 characters (the sign, the digit before the
// decimal point, the decimal point, the exponent character, the
// exponent's sign, and at most 3 exponent digits).
- bool ToExponential(double value,
+ MFBT_API bool ToExponential(double value,
int requested_digits,
StringBuilder* result_builder) const;
// Computes 'precision' leading digits of the given 'value' and returns them
// either in exponential or decimal format, depending on
// max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
// constructor).
// The last computed digit is rounded.
@@ -270,17 +271,17 @@ class DoubleToStringConverter {
// except for the following cases:
// - the input value is special and no infinity_symbol or nan_symbol has
// been provided to the constructor,
// - precision < kMinPericisionDigits
// - precision > kMaxPrecisionDigits
// The last condition implies that the result will never contain more than
// kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
// exponent character, the exponent's sign, and at most 3 exponent digits).
- bool ToPrecision(double value,
+ MFBT_API bool ToPrecision(double value,
int precision,
StringBuilder* result_builder) const;
enum DtoaMode {
// Produce the shortest correct representation.
// For example the output of 0.299999999999999988897 is (the less accurate
// but correct) 0.3.
SHORTEST,
@@ -295,17 +296,17 @@ class DoubleToStringConverter {
};
@@ -51,17 +52,17 @@ class DoubleToStringConverter {
static const int kMaxPrecisionDigits = 120;
// The maximal number of digits that are needed to emit a double in base 10.
// A higher precision can be achieved by using more digits, but the shortest
@ -107,14 +32,90 @@ diff --git a/mfbt/double-conversion/double-conversion/double-to-string.h b/mfbt/
- static const int kBase10MaximalLength = 17;
+ static const MFBT_DATA int kBase10MaximalLength = 17;
// Converts the given double 'v' to digit characters. 'v' must not be NaN,
// +Infinity, or -Infinity. In SHORTEST_SINGLE-mode this restriction also
// applies to 'v' after it has been casted to a single-precision float. That
// is, in this mode static_cast<float>(v) must not be NaN, +Infinity or
// -Infinity.
// The maximal number of digits that are needed to emit a single in base 10.
// A higher precision can be achieved by using more digits, but the shortest
// accurate representation of any single will never use more digits than
// kBase10MaximalLengthSingle.
static const int kBase10MaximalLengthSingle = 9;
// The length of the longest string that 'ToShortest' can produce when the
@@ -167,17 +168,17 @@ class DoubleToStringConverter {
//
// The result should be interpreted as buffer * 10^(point-length).
@@ -340,44 +341,44 @@ class DoubleToStringConverter {
// Flags: UNIQUE_ZERO and EMIT_POSITIVE_EXPONENT_SIGN.
// Special values: "Infinity" and "NaN".
// Lower case 'e' for exponential values.
// decimal_in_shortest_low: -6
// decimal_in_shortest_high: 21
// max_leading_padding_zeroes_in_precision_mode: 6
// max_trailing_padding_zeroes_in_precision_mode: 0
- static const DoubleToStringConverter& EcmaScriptConverter();
+ static MFBT_API const DoubleToStringConverter& EcmaScriptConverter();
// Computes the shortest string of digits that correctly represent the input
// number. Depending on decimal_in_shortest_low and decimal_in_shortest_high
// (see constructor) it then either returns a decimal representation, or an
// exponential representation.
// Example with decimal_in_shortest_low = -6,
// decimal_in_shortest_high = 21,
// EMIT_POSITIVE_EXPONENT_SIGN activated, and
@@ -252,17 +253,17 @@ class DoubleToStringConverter {
// been provided to the constructor,
// - 'value' > 10^kMaxFixedDigitsBeforePoint, or
// - 'requested_digits' > kMaxFixedDigitsAfterPoint.
// The last two conditions imply that the result for non-special values never
// contains more than
// 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
// (one additional character for the sign, and one for the decimal point).
// In addition, the buffer must be able to hold the trailing '\0' character.
- bool ToFixed(double value,
+ MFBT_API bool ToFixed(double value,
int requested_digits,
StringBuilder* result_builder) const;
// Computes a representation in exponential format with requested_digits
// after the decimal point. The last emitted digit is rounded.
// If requested_digits equals -1, then the shortest exponential representation
// is computed.
//
@@ -286,17 +287,17 @@ class DoubleToStringConverter {
// been provided to the constructor,
// - 'requested_digits' > kMaxExponentialDigits.
//
// The last condition implies that the result never contains more than
// kMaxExponentialDigits + 8 characters (the sign, the digit before the
// decimal point, the decimal point, the exponent character, the
// exponent's sign, and at most 3 exponent digits).
// In addition, the buffer must be able to hold the trailing '\0' character.
- bool ToExponential(double value,
+ MFBT_API bool ToExponential(double value,
int requested_digits,
StringBuilder* result_builder) const;
// Computes 'precision' leading digits of the given 'value' and returns them
// either in exponential or decimal format, depending on
// max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
// constructor).
@@ -327,17 +328,17 @@ class DoubleToStringConverter {
// been provided to the constructor,
// - precision < kMinPericisionDigits
// - precision > kMaxPrecisionDigits
//
// The last condition implies that the result never contains more than
// kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
// exponent character, the exponent's sign, and at most 3 exponent digits).
// In addition, the buffer must be able to hold the trailing '\0' character.
- bool ToPrecision(double value,
+ MFBT_API bool ToPrecision(double value,
int precision,
StringBuilder* result_builder) const;
enum DtoaMode {
// Produce the shortest correct representation.
// For example the output of 0.299999999999999988897 is (the less accurate
// but correct) 0.3.
SHORTEST,
@@ -389,44 +390,44 @@ class DoubleToStringConverter {
// DoubleToAscii expects the given buffer to be big enough to hold all
// digits and a terminating null-character. In SHORTEST-mode it expects a
// buffer of at least kBase10MaximalLength + 1. In all other modes the

Просмотреть файл

@ -1,7 +1,8 @@
diff --git a/mfbt/double-conversion/double-conversion/strtod.cc b/mfbt/double-conversion/double-conversion/strtod.cc
index 850bcdaac4ad1..6ed686c8d9bfb 100644
--- a/mfbt/double-conversion/double-conversion/strtod.cc
+++ b/mfbt/double-conversion/double-conversion/strtod.cc
@@ -441,32 +441,34 @@ static bool ComputeGuess(Vector<const ch
@@ -447,32 +447,34 @@ static bool ComputeGuess(Vector<const char> trimmed, int exponent,
return true;
}
if (*guess == Double::Infinity()) {

Просмотреть файл

@ -370,7 +370,7 @@ static void BignumToFixed(int requested_digits, int* decimal_point,
// Returns an estimation of k such that 10^(k-1) <= v < 10^k where
// v = f * 2^exponent and 2^52 <= f < 2^53.
// v is hence a normalized double with the given exponent. The output is an
// approximation for the exponent of the decimal approimation .digits * 10^k.
// approximation for the exponent of the decimal approximation .digits * 10^k.
//
// The result might undershoot by 1 in which case 10^k <= v < 10^k+1.
// Note: this property holds for v's upper boundary m+ too.
@ -548,7 +548,7 @@ static void InitialScaledStartValuesNegativeExponentNegativePower(
//
// Let ep == estimated_power, then the returned values will satisfy:
// v / 10^ep = numerator / denominator.
// v's boundarys m- and m+:
// v's boundaries m- and m+:
// m- / 10^ep == v / 10^ep - delta_minus / denominator
// m+ / 10^ep == v / 10^ep + delta_plus / denominator
// Or in other words:

Просмотреть файл

@ -92,19 +92,19 @@ void DoubleToStringConverter::CreateExponentialRepresentation(
result_builder->AddCharacter('+');
}
}
if (exponent == 0) {
result_builder->AddCharacter('0');
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';
int first_char_pos = kMaxExponentLength;
while (exponent > 0) {
buffer[--first_char_pos] = '0' + (exponent % 10);
exponent /= 10;
if (exponent == 0) {
buffer[--first_char_pos] = '0';
} else {
while (exponent > 0) {
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
@ -329,9 +329,21 @@ bool DoubleToStringConverter::ToPrecision(double value,
int exponent = decimal_point - 1;
int extra_zero = ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) ? 1 : 0;
if ((-decimal_point + 1 > max_leading_padding_zeroes_in_precision_mode_) ||
bool as_exponential =
(-decimal_point + 1 > max_leading_padding_zeroes_in_precision_mode_) ||
(decimal_point - precision + extra_zero >
max_trailing_padding_zeroes_in_precision_mode_)) {
max_trailing_padding_zeroes_in_precision_mode_);
if ((flags_ & NO_TRAILING_ZERO) != 0) {
// Truncate trailing zeros that occur after the decimal point (if exponential,
// that is everything after the first digit).
int stop = as_exponential ? 1 : std::max(1, decimal_point);
while (decimal_rep_length > stop && decimal_rep[decimal_rep_length - 1] == '0') {
--decimal_rep_length;
}
// Clamp precision to avoid the code below re-adding the zeros.
precision = std::min(precision, decimal_rep_length);
}
if (as_exponential) {
// Fill buffer to contain 'precision' digits.
// Usually the buffer is already at the correct length, but 'DoubleToAscii'
// is allowed to return less characters.

Просмотреть файл

@ -51,12 +51,35 @@ class DoubleToStringConverter {
static const int kMinPrecisionDigits = 1;
static const int kMaxPrecisionDigits = 120;
// The maximal number of digits that are needed to emit a double in base 10.
// A higher precision can be achieved by using more digits, but the shortest
// accurate representation of any double will never use more digits than
// kBase10MaximalLength.
// Note that DoubleToAscii null-terminates its input. So the given buffer
// should be at least kBase10MaximalLength + 1 characters long.
static const MFBT_DATA int kBase10MaximalLength = 17;
// The maximal number of digits that are needed to emit a single in base 10.
// A higher precision can be achieved by using more digits, but the shortest
// accurate representation of any single will never use more digits than
// kBase10MaximalLengthSingle.
static const int kBase10MaximalLengthSingle = 9;
// The length of the longest string that 'ToShortest' can produce when the
// converter is instantiated with EcmaScript defaults (see
// 'EcmaScriptConverter')
// This value does not include the trailing '\0' character.
// This amount of characters is needed for negative values that hit the
// 'decimal_in_shortest_low' limit. For example: "-0.0000033333333333333333"
static const int kMaxCharsEcmaScriptShortest = 25;
enum Flags {
NO_FLAGS = 0,
EMIT_POSITIVE_EXPONENT_SIGN = 1,
EMIT_TRAILING_DECIMAL_POINT = 2,
EMIT_TRAILING_ZERO_AFTER_POINT = 4,
UNIQUE_ZERO = 8
UNIQUE_ZERO = 8,
NO_TRAILING_ZERO = 16
};
// Flags should be a bit-or combination of the possible Flags-enum.
@ -68,9 +91,13 @@ class DoubleToStringConverter {
// Example: 2345.0 is converted to "2345.".
// - EMIT_TRAILING_ZERO_AFTER_POINT: in addition to a trailing decimal point
// emits a trailing '0'-character. This flag requires the
// EXMIT_TRAILING_DECIMAL_POINT flag.
// EMIT_TRAILING_DECIMAL_POINT flag.
// Example: 2345.0 is converted to "2345.0".
// - UNIQUE_ZERO: "-0.0" is converted to "0.0".
// - NO_TRAILING_ZERO: Trailing zeros are removed from the fractional portion
// of the result in precision mode. Matches printf's %g.
// When EMIT_TRAILING_ZERO_AFTER_POINT is also given, one trailing zero is
// preserved.
//
// Infinity symbol and nan_symbol provide the string representation for these
// special values. If the string is NULL and the special value is encountered
@ -138,6 +165,14 @@ class DoubleToStringConverter {
}
// Returns a converter following the EcmaScript specification.
//
// Flags: UNIQUE_ZERO and EMIT_POSITIVE_EXPONENT_SIGN.
// Special values: "Infinity" and "NaN".
// Lower case 'e' for exponential values.
// decimal_in_shortest_low: -6
// decimal_in_shortest_high: 21
// max_leading_padding_zeroes_in_precision_mode: 6
// max_trailing_padding_zeroes_in_precision_mode: 0
static MFBT_API const DoubleToStringConverter& EcmaScriptConverter();
// Computes the shortest string of digits that correctly represent the input
@ -163,6 +198,21 @@ class DoubleToStringConverter {
// Returns true if the conversion succeeds. The conversion always succeeds
// except when the input value is special and no infinity_symbol or
// nan_symbol has been given to the constructor.
//
// The length of the longest result is the maximum of the length of the
// following string representations (each with possible examples):
// - NaN and negative infinity: "NaN", "-Infinity", "-inf".
// - -10^(decimal_in_shortest_high - 1):
// "-100000000000000000000", "-1000000000000000.0"
// - the longest string in range [0; -10^decimal_in_shortest_low]. Generally,
// this string is 3 + kBase10MaximalLength - decimal_in_shortest_low.
// (Sign, '0', decimal point, padding zeroes for decimal_in_shortest_low,
// and the significant digits).
// "-0.0000033333333333333333", "-0.0012345678901234567"
// - the longest exponential representation. (A negative number with
// kBase10MaximalLength significant digits).
// "-1.7976931348623157e+308", "-1.7976931348623157E308"
// In addition, the buffer must be able to hold the trailing '\0' character.
bool ToShortest(double value, StringBuilder* result_builder) const {
return ToShortestIeeeNumber(value, result_builder, SHORTEST);
}
@ -203,9 +253,11 @@ class DoubleToStringConverter {
// been provided to the constructor,
// - 'value' > 10^kMaxFixedDigitsBeforePoint, or
// - 'requested_digits' > kMaxFixedDigitsAfterPoint.
// The last two conditions imply that the result will never contain more than
// 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
// The last two conditions imply that the result for non-special values never
// contains more than
// 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters
// (one additional character for the sign, and one for the decimal point).
// In addition, the buffer must be able to hold the trailing '\0' character.
MFBT_API bool ToFixed(double value,
int requested_digits,
StringBuilder* result_builder) const;
@ -234,14 +286,17 @@ class DoubleToStringConverter {
// - the input value is special and no infinity_symbol or nan_symbol has
// been provided to the constructor,
// - 'requested_digits' > kMaxExponentialDigits.
// The last condition implies that the result will never contain more than
//
// The last condition implies that the result never contains more than
// kMaxExponentialDigits + 8 characters (the sign, the digit before the
// decimal point, the decimal point, the exponent character, the
// exponent's sign, and at most 3 exponent digits).
// In addition, the buffer must be able to hold the trailing '\0' character.
MFBT_API bool ToExponential(double value,
int requested_digits,
StringBuilder* result_builder) const;
// Computes 'precision' leading digits of the given 'value' and returns them
// either in exponential or decimal format, depending on
// max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
@ -273,9 +328,11 @@ class DoubleToStringConverter {
// been provided to the constructor,
// - precision < kMinPericisionDigits
// - precision > kMaxPrecisionDigits
// The last condition implies that the result will never contain more than
//
// The last condition implies that the result never contains more than
// kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
// exponent character, the exponent's sign, and at most 3 exponent digits).
// In addition, the buffer must be able to hold the trailing '\0' character.
MFBT_API bool ToPrecision(double value,
int precision,
bool* used_exponential_notation,
@ -296,14 +353,6 @@ class DoubleToStringConverter {
PRECISION
};
// The maximal number of digits that are needed to emit a double in base 10.
// A higher precision can be achieved by using more digits, but the shortest
// accurate representation of any double will never use more digits than
// kBase10MaximalLength.
// Note that DoubleToAscii null-terminates its input. So the given buffer
// should be at least kBase10MaximalLength + 1 characters long.
static const MFBT_DATA int kBase10MaximalLength = 17;
// Converts the given double 'v' to digit characters. 'v' must not be NaN,
// +Infinity, or -Infinity. In SHORTEST_SINGLE-mode this restriction also
// applies to 'v' after it has been casted to a single-precision float. That

Просмотреть файл

@ -45,6 +45,7 @@ class Double {
static const uint64_t kExponentMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x7FF00000, 00000000);
static const uint64_t kSignificandMask = DOUBLE_CONVERSION_UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
static const uint64_t kHiddenBit = DOUBLE_CONVERSION_UINT64_2PART_C(0x00100000, 00000000);
static const uint64_t kQuietNanBit = DOUBLE_CONVERSION_UINT64_2PART_C(0x00080000, 00000000);
static const int kPhysicalSignificandSize = 52; // Excludes the hidden bit.
static const int kSignificandSize = 53;
static const int kExponentBias = 0x3FF + kPhysicalSignificandSize;
@ -148,6 +149,15 @@ class Double {
((d64 & kSignificandMask) != 0);
}
bool IsQuietNan() const {
return IsNan() && ((AsUint64() & kQuietNanBit) != 0);
}
bool IsSignalingNan() const {
return IsNan() && ((AsUint64() & kQuietNanBit) == 0);
}
bool IsInfinite() const {
uint64_t d64 = AsUint64();
return ((d64 & kExponentMask) == kExponentMask) &&
@ -266,6 +276,7 @@ class Single {
static const uint32_t kExponentMask = 0x7F800000;
static const uint32_t kSignificandMask = 0x007FFFFF;
static const uint32_t kHiddenBit = 0x00800000;
static const uint32_t kQuietNanBit = 0x00400000;
static const int kPhysicalSignificandSize = 23; // Excludes the hidden bit.
static const int kSignificandSize = 24;
@ -324,6 +335,15 @@ class Single {
((d32 & kSignificandMask) != 0);
}
bool IsQuietNan() const {
return IsNan() && ((AsUint32() & kQuietNanBit) != 0);
}
bool IsSignalingNan() const {
return IsNan() && ((AsUint32() & kQuietNanBit) == 0);
}
bool IsInfinite() const {
uint32_t d32 = AsUint32();
return ((d32 & kExponentMask) == kExponentMask) &&

Просмотреть файл

@ -35,6 +35,18 @@
#include "strtod.h"
#include "utils.h"
#ifdef _MSC_VER
# if _MSC_VER >= 1900
// Fix MSVC >= 2015 (_MSC_VER == 1900) warning
// C4244: 'argument': conversion from 'const uc16' to 'char', possible loss of data
// against Advance and friends, when instantiated with **it as char, not uc16.
__pragma(warning(disable: 4244))
# endif
# if _MSC_VER <= 1700 // VS2012, see IsDecimalDigitForRadix warning fix, below
# define VS2012_RADIXWARN
# endif
#endif
namespace double_conversion {
namespace {
@ -149,9 +161,9 @@ static double SignedZero(bool sign) {
//
// The function is small and could be inlined, but VS2012 emitted a warning
// because it constant-propagated the radix and concluded that the last
// condition was always true. By moving it into a separate function the
// compiler wouldn't warn anymore.
#ifdef _MSC_VER
// condition was always true. Moving it into a separate function and
// suppressing optimisation keeps the compiler from warning.
#ifdef VS2012_RADIXWARN
#pragma optimize("",off)
static bool IsDecimalDigitForRadix(int c, int radix) {
return '0' <= c && c <= '9' && (c - '0') < radix;
@ -441,11 +453,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 +487,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 +505,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 +561,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
@ -198,12 +202,14 @@ static bool DoubleStrtod(Vector<const char> trimmed,
int exponent,
double* result) {
#if !defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
// Avoid "unused parameter" warnings
(void) trimmed;
(void) exponent;
(void) result;
// On x86 the floating-point stack can be 64 or 80 bits wide. If it is
// 80 bits wide (as is the case on Linux) then double-rounding occurs and the
// result is not accurate.
// We know that Windows32 uses 64 bits and is therefore accurate.
// Note that the ARM simulator is compiled for 32bits. It therefore exhibits
// the same problem.
return false;
#else
if (trimmed.length() <= kMaxExactDoubleIntegerDecimalDigits) {

Просмотреть файл

@ -56,14 +56,28 @@ inline void abort_noreturn() { MOZ_CRASH(); }
#endif
#endif
// Not all compilers support __has_attribute and combining a check for both
// ifdef and __has_attribute on the same preprocessor line isn't portable.
#ifdef __has_attribute
# define DOUBLE_CONVERSION_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
# define DOUBLE_CONVERSION_HAS_ATTRIBUTE(x) 0
#endif
#ifndef DOUBLE_CONVERSION_UNUSED
#ifdef __GNUC__
#if DOUBLE_CONVERSION_HAS_ATTRIBUTE(unused)
#define DOUBLE_CONVERSION_UNUSED __attribute__((unused))
#else
#define DOUBLE_CONVERSION_UNUSED
#endif
#endif
#if DOUBLE_CONVERSION_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,6 +108,7 @@ 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(__ghs) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
@ -102,7 +117,8 @@ int main(int argc, char** argv) {
defined(__AARCH64EL__) || defined(__aarch64__) || defined(__AARCH64EB__) || \
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__)

Просмотреть файл

@ -70,7 +70,7 @@ done
hg addremove "$DEST"
# Note the revision used in this update.
git -C "$LOCAL_CLONE" show > ./GIT-INFO
git -C "$LOCAL_CLONE" show -s > ./GIT-INFO
# Delete the tmpdir.
rm -rf "$TMPDIR"

Просмотреть файл

@ -1,4 +1,5 @@
diff --git a/mfbt/double-conversion/double-conversion/utils.h b/mfbt/double-conversion/double-conversion/utils.h
index c72c333f020a1..6022132e2b495 100644
--- a/mfbt/double-conversion/double-conversion/utils.h
+++ b/mfbt/double-conversion/double-conversion/utils.h
@@ -26,38 +26,38 @@
@ -40,8 +41,8 @@ diff --git a/mfbt/double-conversion/double-conversion/utils.h b/mfbt/double-conv
#endif
#endif
#ifndef DOUBLE_CONVERSION_UNUSED
#ifdef __GNUC__
#define DOUBLE_CONVERSION_UNUSED __attribute__((unused))
// Not all compilers support __has_attribute and combining a check for both
// ifdef and __has_attribute on the same preprocessor line isn't portable.
#ifdef __has_attribute
# define DOUBLE_CONVERSION_HAS_ATTRIBUTE(x) __has_attribute(x)
#else
#define DOUBLE_CONVERSION_UNUSED