mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-13 18:27:35 +00:00
36462015eb
--HG-- extra : rebase_source : ae21e264fc97373f42ea4a01189caed48e785e9c
167 lines
8.3 KiB
Diff
167 lines
8.3 KiB
Diff
diff --git a/mfbt/double-conversion/double-conversion/double-conversion.h b/mfbt/double-conversion/double-conversion/double-conversion.h
|
|
--- a/mfbt/double-conversion/double-conversion/double-conversion.h
|
|
+++ b/mfbt/double-conversion/double-conversion/double-conversion.h
|
|
@@ -23,16 +23,17 @@
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
|
|
#define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
|
|
|
|
+#include "mozilla/Types.h"
|
|
#include <double-conversion/utils.h>
|
|
|
|
namespace double_conversion {
|
|
|
|
class DoubleToStringConverter {
|
|
public:
|
|
// When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
|
|
// or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
|
|
@@ -124,17 +125,17 @@ class DoubleToStringConverter {
|
|
max_trailing_padding_zeroes_in_precision_mode) {
|
|
// When 'trailing zero after the point' is set, then 'trailing point'
|
|
// must be set too.
|
|
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
|
|
@@ -192,17 +193,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.
|
|
//
|
|
@@ -224,17 +225,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.
|
|
@@ -262,17 +263,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,
|
|
@@ -287,17 +288,17 @@ class DoubleToStringConverter {
|
|
};
|
|
|
|
// 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 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 result should be interpreted as buffer * 10^(point-length).
|
|
@@ -332,44 +333,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
|
|
// requested_digits parameter and the padding-zeroes limit the size of the
|
|
// output. Don't forget the decimal point, the exponent character and the
|
|
// terminating null-character when computing the maximal output size.
|
|
// The given length is only used in debug mode to ensure the buffer is big
|
|
// enough.
|
|
- static void DoubleToAscii(double v,
|
|
+ static MFBT_API void DoubleToAscii(double v,
|
|
DtoaMode mode,
|
|
int requested_digits,
|
|
char* buffer,
|
|
int buffer_length,
|
|
bool* sign,
|
|
int* length,
|
|
int* point);
|
|
|
|
private:
|
|
// Implementation for ToShortest and ToShortestSingle.
|
|
- bool ToShortestIeeeNumber(double value,
|
|
+ MFBT_API bool ToShortestIeeeNumber(double value,
|
|
StringBuilder* result_builder,
|
|
DtoaMode mode) const;
|
|
|
|
// If the value is a special value (NaN or Infinity) constructs the
|
|
// corresponding string using the configured infinity/nan-symbol.
|
|
// If either of them is NULL or the value is not special then the
|
|
// function returns false.
|
|
- bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
|
|
+ MFBT_API bool HandleSpecialValues(double value, StringBuilder* result_builder) const;
|
|
// Constructs an exponential representation (i.e. 1.234e56).
|
|
// The given exponent assumes a decimal point after the first decimal digit.
|
|
- void CreateExponentialRepresentation(const char* decimal_digits,
|
|
+ MFBT_API void CreateExponentialRepresentation(const char* decimal_digits,
|
|
int length,
|
|
int exponent,
|
|
StringBuilder* result_builder) const;
|
|
// Creates a decimal representation (i.e 1234.5678).
|
|
- void CreateDecimalRepresentation(const char* decimal_digits,
|
|
+ MFBT_API void CreateDecimalRepresentation(const char* decimal_digits,
|
|
int length,
|
|
int decimal_point,
|
|
int digits_after_point,
|
|
StringBuilder* result_builder) const;
|
|
|
|
const int flags_;
|
|
const char* const infinity_symbol_;
|
|
const char* const nan_symbol_;
|