1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMBER_DECNUM_H__
8 #define __NUMBER_DECNUM_H__
10 #include "decNumber.h"
15 #define DECNUM_INITIAL_CAPACITY 34
17 // Export an explicit template instantiation of the MaybeStackHeaderAndArray that is used as a data member of DecNum.
18 // When building DLLs for Windows this is required even though no direct access to the MaybeStackHeaderAndArray leaks out of the i18n library.
19 // (See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples.)
20 #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
21 template class U_I18N_API MaybeStackHeaderAndArray
<decNumber
, char, DECNUM_INITIAL_CAPACITY
>;
27 /** A very thin C++ wrapper around decNumber.h */
28 // Exported as U_I18N_API for tests
29 class U_I18N_API DecNum
: public UMemory
{
31 DecNum(); // leaves object in valid but undefined state
33 // Copy-like constructor; use the default move operators.
34 DecNum(const DecNum
& other
, UErrorCode
& status
);
36 /** Sets the decNumber to the StringPiece. */
37 void setTo(StringPiece str
, UErrorCode
& status
);
39 /** Sets the decNumber to the NUL-terminated char string. */
40 void setTo(const char* str
, UErrorCode
& status
);
42 /** Uses double_conversion to set this decNumber to the given double. */
43 void setTo(double d
, UErrorCode
& status
);
45 /** Sets the decNumber to the BCD representation. */
46 void setTo(const uint8_t* bcd
, int32_t length
, int32_t scale
, bool isNegative
, UErrorCode
& status
);
50 void multiplyBy(const DecNum
& rhs
, UErrorCode
& status
);
52 void divideBy(const DecNum
& rhs
, UErrorCode
& status
);
54 bool isNegative() const;
58 inline const decNumber
* getRawDecNumber() const {
59 return fData
.getAlias();
63 static constexpr int32_t kDefaultDigits
= DECNUM_INITIAL_CAPACITY
;
64 MaybeStackHeaderAndArray
<decNumber
, char, kDefaultDigits
> fData
;
67 void _setTo(const char* str
, int32_t maxDigits
, UErrorCode
& status
);
75 #endif // __NUMBER_DECNUM_H__
77 #endif /* #if !UCONFIG_NO_FORMATTING */