1 // © 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
), fFormatFullPrecision(TRUE
) { }
40 UBool
isNegative() const;
42 UBool
isInfinite() const;
43 UBool
isNaNOrInfinity() const;
44 UBool
formatFullPrecision() const; // Apple
47 * Gets the digit at particular exponent, if number is 987.6, then
48 * getDigit(2) == 9 and gitDigit(0) == 7 and gitDigit(-1) == 6.
49 * If isNaN() or isInfinity() return TRUE, then the result of this
50 * function is undefined.
52 int32_t getDigitByExponent(int32_t digitPos
) const;
55 * Returns the digit interval which indicates the leftmost and rightmost
56 * position of this instance.
57 * If isNaN() or isInfinity() return TRUE, then the result of this
58 * function is undefined.
60 const DigitInterval
&getInterval() const { return fInterval
; }
63 * Gets the parameters needed to create a FixedDecimal.
65 void getFixedDecimal(double &source
, int64_t &intValue
, int64_t &f
, int64_t &t
, int32_t &v
, UBool
&hasIntValue
) const;
70 * The digits, least significant first. Both the least and most
71 * significant digit in this list are non-zero; however, digits in the
72 * middle may be zero. This field contains values between (char) 0, and
78 * The range of displayable digits. This field is needed to account for
79 * any leading and trailing zeros which are not stored in fDigits.
81 DigitInterval fInterval
;
84 * The exponent value of the least significant digit in fDigits. For
85 * example, fExponent = 2 and fDigits = {7, 8, 5} represents 58700.
90 * Contains flags such as NaN, Inf, and negative.
95 * Contains the absolute value of the digits left of the decimal place
96 * if fAbsIntValueSet is TRUE
101 * Indicates whether or not fAbsIntValue is set.
103 UBool fAbsIntValueSet
;
106 * Contains the absolute value of the value this instance represents
107 * if fAbsDoubleValueSet is TRUE
109 double fAbsDoubleValue
;
112 * Indicates whether or not fAbsDoubleValue is set.
114 UBool fAbsDoubleValueSet
;
116 // Flag to cap double conversion precision at DBL_DIG digits (Apple specific)
117 UBool fFormatFullPrecision
;
118 void setFormatFullPrecision(UBool formatFullPrecision
);
124 double computeAbsDoubleValue() const;
125 UBool
isOverMaxDigits() const;
127 VisibleDigits(const VisibleDigits
&);
128 VisibleDigits
&operator=(const VisibleDigits
&);
130 friend class FixedPrecision
;
131 friend class VisibleDigitsWithExponent
;
135 * A VisibleDigits with a possible exponent.
137 class U_I18N_API VisibleDigitsWithExponent
: public UMemory
{
139 VisibleDigitsWithExponent() : fHasExponent(FALSE
) { }
140 const VisibleDigits
&getMantissa() const { return fMantissa
; }
141 const VisibleDigits
*getExponent() const {
142 return fHasExponent
? &fExponent
: NULL
;
147 fHasExponent
= FALSE
;
149 UBool
isNegative() const { return fMantissa
.isNegative(); }
150 UBool
isNaN() const { return fMantissa
.isNaN(); }
151 UBool
isInfinite() const { return fMantissa
.isInfinite(); }
152 void setFormatFullPrecision(UBool formatFullPrecision
) { fMantissa
.setFormatFullPrecision(formatFullPrecision
); }
154 VisibleDigitsWithExponent(const VisibleDigitsWithExponent
&);
155 VisibleDigitsWithExponent
&operator=(
156 const VisibleDigitsWithExponent
&);
157 VisibleDigits fMantissa
;
158 VisibleDigits fExponent
;
161 friend class ScientificPrecision
;
162 friend class FixedPrecision
;
167 #endif /* #if !UCONFIG_NO_FORMATTING */
168 #endif // __VISIBLEDIGITS_H__