| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
#include "unicode/utypes.h" |
| 5 |
|
| 6 |
#if !UCONFIG_NO_FORMATTING |
| 7 |
#ifndef __NUMBER_DECNUM_H__ |
| 8 |
#define __NUMBER_DECNUM_H__ |
| 9 |
|
| 10 |
#include "decNumber.h" |
| 11 |
#include "charstr.h" |
| 12 |
#include "bytesinkutil.h" |
| 13 |
|
| 14 |
U_NAMESPACE_BEGIN |
| 15 |
|
| 16 |
#define DECNUM_INITIAL_CAPACITY 34 |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN |
| 22 |
template class U_I18N_API MaybeStackHeaderAndArray<decNumber, char, DECNUM_INITIAL_CAPACITY>; |
| 23 |
#endif |
| 24 |
|
| 25 |
namespace number::impl { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
class U_I18N_API DecNum : public UMemory { |
| 30 |
public: |
| 31 |
DecNum(); |
| 32 |
|
| 33 |
|
| 34 |
DecNum(const DecNum& other, UErrorCode& status); |
| 35 |
|
| 36 |
|
| 37 |
void setTo(StringPiece str, UErrorCode& status); |
| 38 |
|
| 39 |
|
| 40 |
void setTo(const char* str, UErrorCode& status); |
| 41 |
|
| 42 |
|
| 43 |
void setTo(double d, UErrorCode& status); |
| 44 |
|
| 45 |
|
| 46 |
void setTo(const uint8_t* bcd, int32_t length, int32_t scale, bool isNegative, UErrorCode& status); |
| 47 |
|
| 48 |
void normalize(); |
| 49 |
|
| 50 |
void multiplyBy(const DecNum& rhs, UErrorCode& status); |
| 51 |
|
| 52 |
void divideBy(const DecNum& rhs, UErrorCode& status); |
| 53 |
|
| 54 |
bool isNegative() const; |
| 55 |
|
| 56 |
bool isZero() const; |
| 57 |
|
| 58 |
|
| 59 |
bool isSpecial() const; |
| 60 |
|
| 61 |
bool isInfinity() const; |
| 62 |
|
| 63 |
bool isNaN() const; |
| 64 |
|
| 65 |
void toString(ByteSink& output, UErrorCode& status) const; |
| 66 |
|
| 67 |
inline CharString toCharString(UErrorCode& status) const { |
| 68 |
CharString cstr; |
| 69 |
CharStringByteSink sink(&cstr); |
| 70 |
toString(sink, status); |
| 71 |
return cstr; |
| 72 |
} |
| 73 |
|
| 74 |
inline const decNumber* getRawDecNumber() const { |
| 75 |
return fData.getAlias(); |
| 76 |
} |
| 77 |
|
| 78 |
private: |
| 79 |
static constexpr int32_t kDefaultDigits = DECNUM_INITIAL_CAPACITY; |
| 80 |
MaybeStackHeaderAndArray<decNumber, char, kDefaultDigits> fData; |
| 81 |
decContext fContext; |
| 82 |
|
| 83 |
void _setTo(const char* str, int32_t maxDigits, UErrorCode& status); |
| 84 |
}; |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
U_NAMESPACE_END |
| 89 |
|
| 90 |
#endif |
| 91 |
|
| 92 |
#endif |