2 ******************************************************************************* * Copyright (C) 2015, International Business Machines
3 * Corporation and others. All Rights Reserved.
4 *******************************************************************************
7 * created on: 2015jun20
8 * created by: Travis Keep
11 #ifndef __VISIBLEDIGITS_H__
12 #define __VISIBLEDIGITS_H__
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_FORMATTING
18 #include "unicode/uobject.h"
21 #include "digitinterval.h"
28 * VisibleDigits represents the digits visible for formatting.
29 * Once initialized using a FixedPrecision instance, VisibleDigits instances
30 * remain unchanged until they are initialized again. A VisibleDigits with
31 * a numeric value equal to 3.0 could be "3", "3.0", "3.00" or even "003.0"
32 * depending on settings of the FixedPrecision instance used to initialize it.
34 class U_I18N_API VisibleDigits
: public UMemory
{
36 VisibleDigits() : fExponent(0), fFlags(0), fAbsIntValue(0), fAbsIntValueSet(FALSE
), fAbsDoubleValue(0.0), fAbsDoubleValueSet(FALSE
) { }
38 UBool
isNegative() const;
40 UBool
isInfinite() const;
41 UBool
isNaNOrInfinity() const;
44 * Gets the digit at particular exponent, if number is 987.6, then
45 * getDigit(2) == 9 and gitDigit(0) == 7 and gitDigit(-1) == 6.
46 * If isNaN() or isInfinity() return TRUE, then the result of this
47 * function is undefined.
49 int32_t getDigitByExponent(int32_t digitPos
) const;
52 * Returns the digit interval which indicates the leftmost and rightmost
53 * position of this instance.
54 * If isNaN() or isInfinity() return TRUE, then the result of this
55 * function is undefined.
57 const DigitInterval
&getInterval() const { return fInterval
; }
60 * Gets the parameters needed to create a FixedDecimal.
62 void getFixedDecimal(double &source
, int64_t &intValue
, int64_t &f
, int64_t &t
, int32_t &v
, UBool
&hasIntValue
) const;
67 * The digits, least significant first. Both the least and most
68 * significant digit in this list are non-zero; however, digits in the
69 * middle may be zero. This field contains values between (char) 0, and
75 * The range of displayable digits. This field is needed to account for
76 * any leading and trailing zeros which are not stored in fDigits.
78 DigitInterval fInterval
;
81 * The exponent value of the least significant digit in fDigits. For
82 * example, fExponent = 2 and fDigits = {7, 8, 5} represents 58700.
87 * Contains flags such as NaN, Inf, and negative.
92 * Contains the absolute value of the digits left of the decimal place
93 * if fAbsIntValueSet is TRUE
98 * Indicates whether or not fAbsIntValue is set.
100 UBool fAbsIntValueSet
;
103 * Contains the absolute value of the value this instance represents
104 * if fAbsDoubleValueSet is TRUE
106 double fAbsDoubleValue
;
109 * Indicates whether or not fAbsDoubleValue is set.
111 UBool fAbsDoubleValueSet
;
117 double computeAbsDoubleValue() const;
118 UBool
isOverMaxDigits() const;
120 VisibleDigits(const VisibleDigits
&);
121 VisibleDigits
&operator=(const VisibleDigits
&);
123 friend class FixedPrecision
;
124 friend class VisibleDigitsWithExponent
;
128 * A VisibleDigits with a possible exponent.
130 class U_I18N_API VisibleDigitsWithExponent
: public UMemory
{
132 VisibleDigitsWithExponent() : fHasExponent(FALSE
) { }
133 const VisibleDigits
&getMantissa() const { return fMantissa
; }
134 const VisibleDigits
*getExponent() const {
135 return fHasExponent
? &fExponent
: NULL
;
140 fHasExponent
= FALSE
;
142 UBool
isNegative() const { return fMantissa
.isNegative(); }
143 UBool
isNaN() const { return fMantissa
.isNaN(); }
144 UBool
isInfinite() const { return fMantissa
.isInfinite(); }
146 VisibleDigitsWithExponent(const VisibleDigitsWithExponent
&);
147 VisibleDigitsWithExponent
&operator=(
148 const VisibleDigitsWithExponent
&);
149 VisibleDigits fMantissa
;
150 VisibleDigits fExponent
;
153 friend class ScientificPrecision
;
154 friend class FixedPrecision
;
159 #endif /* #if !UCONFIG_NO_FORMATTING */
160 #endif // __VISIBLEDIGITS_H__