1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************* * Copyright (C) 2015, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *******************************************************************************
9 * created on: 2015jun20
10 * created by: Travis Keep
13 #ifndef __VISIBLEDIGITS_H__
14 #define __VISIBLEDIGITS_H__
16 #include "unicode/utypes.h"
18 #if !UCONFIG_NO_FORMATTING
20 #include "unicode/uobject.h"
23 #include "digitinterval.h"
30 * VisibleDigits represents the digits visible for formatting.
31 * Once initialized using a FixedPrecision instance, VisibleDigits instances
32 * remain unchanged until they are initialized again. A VisibleDigits with
33 * a numeric value equal to 3.0 could be "3", "3.0", "3.00" or even "003.0"
34 * depending on settings of the FixedPrecision instance used to initialize it.
36 class U_I18N_API VisibleDigits : public UMemory {
38 VisibleDigits() : fExponent(0), fFlags(0), fAbsIntValue(0), fAbsIntValueSet(FALSE), fAbsDoubleValue(0.0), fAbsDoubleValueSet(FALSE) { }
40 UBool isNegative() const;
42 UBool isInfinite() const;
43 UBool isNaNOrInfinity() const;
46 * Gets the digit at particular exponent, if number is 987.6, then
47 * getDigit(2) == 9 and gitDigit(0) == 7 and gitDigit(-1) == 6.
48 * If isNaN() or isInfinity() return TRUE, then the result of this
49 * function is undefined.
51 int32_t getDigitByExponent(int32_t digitPos) const;
54 * Returns the digit interval which indicates the leftmost and rightmost
55 * position of this instance.
56 * If isNaN() or isInfinity() return TRUE, then the result of this
57 * function is undefined.
59 const DigitInterval &getInterval() const { return fInterval; }
62 * Gets the parameters needed to create a FixedDecimal.
64 void getFixedDecimal(double &source, int64_t &intValue, int64_t &f, int64_t &t, int32_t &v, UBool &hasIntValue) const;
69 * The digits, least significant first. Both the least and most
70 * significant digit in this list are non-zero; however, digits in the
71 * middle may be zero. This field contains values between (char) 0, and
77 * The range of displayable digits. This field is needed to account for
78 * any leading and trailing zeros which are not stored in fDigits.
80 DigitInterval fInterval;
83 * The exponent value of the least significant digit in fDigits. For
84 * example, fExponent = 2 and fDigits = {7, 8, 5} represents 58700.
89 * Contains flags such as NaN, Inf, and negative.
94 * Contains the absolute value of the digits left of the decimal place
95 * if fAbsIntValueSet is TRUE
100 * Indicates whether or not fAbsIntValue is set.
102 UBool fAbsIntValueSet;
105 * Contains the absolute value of the value this instance represents
106 * if fAbsDoubleValueSet is TRUE
108 double fAbsDoubleValue;
111 * Indicates whether or not fAbsDoubleValue is set.
113 UBool fAbsDoubleValueSet;
119 double computeAbsDoubleValue() const;
120 UBool isOverMaxDigits() const;
122 VisibleDigits(const VisibleDigits &);
123 VisibleDigits &operator=(const VisibleDigits &);
125 friend class FixedPrecision;
126 friend class VisibleDigitsWithExponent;
130 * A VisibleDigits with a possible exponent.
132 class U_I18N_API VisibleDigitsWithExponent : public UMemory {
134 VisibleDigitsWithExponent() : fHasExponent(FALSE) { }
135 const VisibleDigits &getMantissa() const { return fMantissa; }
136 const VisibleDigits *getExponent() const {
137 return fHasExponent ? &fExponent : NULL;
142 fHasExponent = FALSE;
144 UBool isNegative() const { return fMantissa.isNegative(); }
145 UBool isNaN() const { return fMantissa.isNaN(); }
146 UBool isInfinite() const { return fMantissa.isInfinite(); }
148 VisibleDigitsWithExponent(const VisibleDigitsWithExponent &);
149 VisibleDigitsWithExponent &operator=(
150 const VisibleDigitsWithExponent &);
151 VisibleDigits fMantissa;
152 VisibleDigits fExponent;
155 friend class ScientificPrecision;
156 friend class FixedPrecision;
161 #endif /* #if !UCONFIG_NO_FORMATTING */
162 #endif // __VISIBLEDIGITS_H__