summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/i18n/number_decimalquantity.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/icu-small/source/i18n/number_decimalquantity.h')
-rw-r--r--deps/icu-small/source/i18n/number_decimalquantity.h92
1 files changed, 66 insertions, 26 deletions
diff --git a/deps/icu-small/source/i18n/number_decimalquantity.h b/deps/icu-small/source/i18n/number_decimalquantity.h
index 4309c3c638..8e04dea7eb 100644
--- a/deps/icu-small/source/i18n/number_decimalquantity.h
+++ b/deps/icu-small/source/i18n/number_decimalquantity.h
@@ -3,13 +3,12 @@
#include "unicode/utypes.h"
-#if !UCONFIG_NO_FORMATTING && !UPRV_INCOMPLETE_CPP11_SUPPORT
+#if !UCONFIG_NO_FORMATTING
#ifndef __NUMBER_DECIMALQUANTITY_H__
#define __NUMBER_DECIMALQUANTITY_H__
#include <cstdint>
#include "unicode/umachine.h"
-#include "decNumber.h"
#include "standardplural.h"
#include "plurrule_impl.h"
#include "number_types.h"
@@ -17,6 +16,9 @@
U_NAMESPACE_BEGIN namespace number {
namespace impl {
+// Forward-declare (maybe don't want number_utils.h included here):
+class DecNum;
+
/**
* An class for representing a number to be processed by the decimal formatting pipeline. Includes
* methods for rounding, plural rules, and decimal digit extraction.
@@ -33,9 +35,12 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
/** Copy constructor. */
DecimalQuantity(const DecimalQuantity &other);
+ /** Move constructor. */
+ DecimalQuantity(DecimalQuantity &&src) U_NOEXCEPT;
+
DecimalQuantity();
- ~DecimalQuantity();
+ ~DecimalQuantity() override;
/**
* Sets this instance to be equal to another instance.
@@ -44,6 +49,9 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
*/
DecimalQuantity &operator=(const DecimalQuantity &other);
+ /** Move assignment */
+ DecimalQuantity &operator=(DecimalQuantity&& src) U_NOEXCEPT;
+
/**
* Sets the minimum and maximum integer digits that this {@link DecimalQuantity} should generate.
* This method does not perform rounding.
@@ -71,7 +79,10 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
* @param mathContext The {@link RoundingMode} to use if rounding is necessary.
*/
void roundToIncrement(double roundingIncrement, RoundingMode roundingMode,
- int32_t minMaxFrac, UErrorCode& status);
+ int32_t maxFrac, UErrorCode& status);
+
+ /** Removes all fraction digits. */
+ void truncate();
/**
* Rounds the number to a specified magnitude (power of ten).
@@ -89,19 +100,30 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
void roundToInfinity();
/**
- * Multiply the internal value.
+ * Multiply the internal value. Uses decNumber.
+ *
+ * @param multiplicand The value by which to multiply.
+ */
+ void multiplyBy(const DecNum& multiplicand, UErrorCode& status);
+
+ /**
+ * Divide the internal value. Uses decNumber.
*
* @param multiplicand The value by which to multiply.
*/
- void multiplyBy(int32_t multiplicand);
+ void divideBy(const DecNum& divisor, UErrorCode& status);
+
+ /** Flips the sign from positive to negative and back. */
+ void negate();
/**
* Scales the number by a power of ten. For example, if the value is currently "1234.56", calling
* this method with delta=-3 will change the value to "1.23456".
*
* @param delta The number of magnitudes of ten to change by.
+ * @return true if integer overflow occured; false otherwise.
*/
- void adjustMagnitude(int32_t delta);
+ bool adjustMagnitude(int32_t delta);
/**
* @return The power of ten corresponding to the most significant nonzero digit.
@@ -124,13 +146,23 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
/** @return Whether the value represented by this {@link DecimalQuantity} is not a number. */
bool isNaN() const U_OVERRIDE;
- int64_t toLong() const;
+ /** @param truncateIfOverflow if false and the number does NOT fit, fails with an assertion error. */
+ int64_t toLong(bool truncateIfOverflow = false) const;
- int64_t toFractionLong(bool includeTrailingZeros) const;
+ uint64_t toFractionLong(bool includeTrailingZeros) const;
+
+ /**
+ * Returns whether or not a Long can fully represent the value stored in this DecimalQuantity.
+ * @param ignoreFraction if true, silently ignore digits after the decimal place.
+ */
+ bool fitsInLong(bool ignoreFraction = false) const;
/** @return The value contained in this {@link DecimalQuantity} approximated as a double. */
double toDouble() const;
+ /** Computes a DecNum representation of this DecimalQuantity, saving it to the output parameter. */
+ void toDecNum(DecNum& output, UErrorCode& status) const;
+
DecimalQuantity &setToInt(int32_t n);
DecimalQuantity &setToLong(int64_t n);
@@ -138,8 +170,10 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
DecimalQuantity &setToDouble(double n);
/** decNumber is similar to BigDecimal in Java. */
+ DecimalQuantity &setToDecNumber(StringPiece n, UErrorCode& status);
- DecimalQuantity &setToDecNumber(StringPiece n);
+ /** Internal method if the caller already has a DecNum. */
+ DecimalQuantity &setToDecNum(const DecNum& n, UErrorCode& status);
/**
* Appends a digit, optionally with one or more leading zeros, to the end of the value represented
@@ -160,17 +194,10 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
*/
void appendDigit(int8_t value, int32_t leadingZeros, bool appendAsInteger);
- /**
- * Computes the plural form for this number based on the specified set of rules.
- *
- * @param rules A {@link PluralRules} object representing the set of rules.
- * @return The {@link StandardPlural} according to the PluralRules. If the plural form is not in
- * the set of standard plurals, {@link StandardPlural#OTHER} is returned instead.
- */
- StandardPlural::Form getStandardPlural(const PluralRules *rules) const;
-
double getPluralOperand(PluralOperand operand) const U_OVERRIDE;
+ bool hasIntegerValue() const U_OVERRIDE;
+
/**
* Gets the digit at the specified magnitude. For example, if the represented number is 12.3,
* getDigit(-1) returns 3, since 3 is the digit corresponding to 10^-1.
@@ -223,10 +250,10 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
UnicodeString toString() const;
- /* Returns the string in exponential notation. */
- UnicodeString toNumberString() const;
+ /** Returns the string in standard exponential notation. */
+ UnicodeString toScientificString() const;
- /* Returns the string without exponential notation. Slightly slower than toNumberString(). */
+ /** Returns the string without exponential notation. Slightly slower than toScientificString(). */
UnicodeString toPlainString() const;
/** Visible for testing */
@@ -235,6 +262,17 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
/** Visible for testing */
inline bool isExplicitExactDouble() { return explicitExactDouble; };
+ bool operator==(const DecimalQuantity& other) const;
+
+ inline bool operator!=(const DecimalQuantity& other) const {
+ return !(*this == other);
+ }
+
+ /**
+ * Bogus flag for when a DecimalQuantity is stored on the stack.
+ */
+ bool bogus = false;
+
private:
/**
* The power of ten corresponding to the least significant digit in the BCD. For example, if this
@@ -396,12 +434,16 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
*/
void readLongToBcd(int64_t n);
- void readDecNumberToBcd(decNumber *dn);
+ void readDecNumberToBcd(const DecNum& dn);
void readDoubleConversionToBcd(const char* buffer, int32_t length, int32_t point);
+ void copyFieldsFrom(const DecimalQuantity& other);
+
void copyBcdFrom(const DecimalQuantity &other);
+ void moveBcdFrom(DecimalQuantity& src);
+
/**
* Removes trailing zeros from the BCD (adjusting the scale as required) and then computes the
* precision. The precision is the number of digits in the number up through the greatest nonzero
@@ -418,12 +460,10 @@ class U_I18N_API DecimalQuantity : public IFixedDecimal, public UMemory {
void _setToDoubleFast(double n);
- void _setToDecNumber(decNumber *n);
+ void _setToDecNum(const DecNum& dn, UErrorCode& status);
void convertToAccurateDouble();
- double toDoubleFromOriginal() const;
-
/** Ensure that a byte array of at least 40 digits is allocated. */
void ensureCapacity();