1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #if !defined(DECNUMBER)
23 # define DECNUMBER
24 # define DECNAME "decNumber"
25 # define DECFULLNAME "Decimal Number Module"
26 # define DECAUTHOR "Mike Cowlishaw"
27
28 # if !defined(DECCONTEXT)
29 # include "decContext.h"
30 # endif
31
32
33 # define DECNEG 0x80
34 # define DECINF 0x40
35 # define DECNAN 0x20
36 # define DECSNAN 0x10
37
38 # define DECSPECIAL (DECINF|DECNAN|DECSNAN)
39
40
41
42
43
44
45
46 # define DECDPUN 8
47
48
49
50
51
52
53 # if !defined(DECNUMDIGITS)
54 # define DECNUMDIGITS 1
55 # endif
56
57
58
59 # if DECDPUN<=2
60 # define decNumberUnit uint8_t
61 # elif DECDPUN<=4
62 # define decNumberUnit uint16_t
63 # else
64 # define decNumberUnit uint32_t
65 # endif
66
67 # define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)
68
69
70 typedef struct {
71 int32_t digits;
72 int32_t exponent;
73
74 uint8_t bits;
75
76 decNumberUnit lsu[DECNUMUNITS];
77 } decNumber;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 decNumber * decNumberFromInt32(decNumber *, int32_t);
102 decNumber * decNumberFromUInt32(decNumber *, uint32_t);
103 decNumber * decNumberFromString(decNumber *, const char *, decContext *);
104 char * decNumberToString(const decNumber *, char *);
105 char * decNumberToEngString(const decNumber *, char *);
106 uint32_t decNumberToUInt32(const decNumber *, decContext *);
107 int32_t decNumberToInt32(const decNumber *, decContext *);
108 uint8_t * decNumberGetBCD(const decNumber *, uint8_t *);
109 decNumber * decNumberSetBCD(decNumber *, const uint8_t *, uint32_t);
110
111
112 decNumber * decNumberAbs(decNumber *, const decNumber *, decContext *);
113 decNumber * decNumberAdd(decNumber *, const decNumber *, const decNumber *, decContext *);
114 decNumber * decNumberAnd(decNumber *, const decNumber *, const decNumber *, decContext *);
115 decNumber * decNumberCompare(decNumber *, const decNumber *, const decNumber *, decContext *);
116 decNumber * decNumberCompareSignal(decNumber *, const decNumber *, const decNumber *, decContext *);
117 decNumber * decNumberCompareTotal(decNumber *, const decNumber *, const decNumber *, decContext *);
118 decNumber * decNumberCompareTotalMag(decNumber *, const decNumber *, const decNumber *, decContext *);
119 decNumber * decNumberDivide(decNumber *, const decNumber *, const decNumber *, decContext *);
120 decNumber * decNumberDivideInteger(decNumber *, const decNumber *, const decNumber *, decContext *);
121 decNumber * decNumberExp(decNumber *, const decNumber *, decContext *);
122 decNumber * decNumberFMA(decNumber *, const decNumber *, const decNumber *, const decNumber *, decContext *);
123 decNumber * decNumberInvert(decNumber *, const decNumber *, decContext *);
124 decNumber * decNumberLn(decNumber *, const decNumber *, decContext *);
125 decNumber * decNumberLogB(decNumber *, const decNumber *, decContext *);
126 decNumber * decNumberLog10(decNumber *, const decNumber *, decContext *);
127 decNumber * decNumberMax(decNumber *, const decNumber *, const decNumber *, decContext *);
128 decNumber * decNumberMaxMag(decNumber *, const decNumber *, const decNumber *, decContext *);
129 decNumber * decNumberMin(decNumber *, const decNumber *, const decNumber *, decContext *);
130 decNumber * decNumberMinMag(decNumber *, const decNumber *, const decNumber *, decContext *);
131 decNumber * decNumberMinus(decNumber *, const decNumber *, decContext *);
132 decNumber * decNumberMultiply(decNumber *, const decNumber *, const decNumber *, decContext *);
133 decNumber * decNumberNormalize(decNumber *, const decNumber *, decContext *);
134 decNumber * decNumberOr(decNumber *, const decNumber *, const decNumber *, decContext *);
135 decNumber * decNumberPlus(decNumber *, const decNumber *, decContext *);
136 decNumber * decNumberPower(decNumber *, const decNumber *, const decNumber *, decContext *);
137 decNumber * decNumberQuantize(decNumber *, const decNumber *, const decNumber *, decContext *);
138 decNumber * decNumberReduce(decNumber *, const decNumber *, decContext *);
139 decNumber * decNumberRemainder(decNumber *, const decNumber *, const decNumber *, decContext *);
140 decNumber * decNumberRemainderNear(decNumber *, const decNumber *, const decNumber *, decContext *);
141 decNumber * decNumberRescale(decNumber *, const decNumber *, const decNumber *, decContext *);
142 decNumber * decNumberRotate(decNumber *, const decNumber *, const decNumber *, decContext *);
143 decNumber * decNumberSameQuantum(decNumber *, const decNumber *, const decNumber *);
144 decNumber * decNumberScaleB(decNumber *, const decNumber *, const decNumber *, decContext *);
145 decNumber * decNumberShift(decNumber *, const decNumber *, const decNumber *, decContext *);
146 decNumber * decNumberSquareRoot(decNumber *, const decNumber *, decContext *);
147 decNumber * decNumberSubtract(decNumber *, const decNumber *, const decNumber *, decContext *);
148 decNumber * decNumberToIntegralExact(decNumber *, const decNumber *, decContext *);
149 decNumber * decNumberToIntegralValue(decNumber *, const decNumber *, decContext *);
150 decNumber * decNumberXor(decNumber *, const decNumber *, const decNumber *, decContext *);
151
152
153 enum decClass decNumberClass(const decNumber *, decContext *);
154 const char * decNumberClassToString(enum decClass);
155 decNumber * decNumberCopy(decNumber *, const decNumber *);
156 decNumber * decNumberCopyAbs(decNumber *, const decNumber *);
157 decNumber * decNumberCopyNegate(decNumber *, const decNumber *);
158 decNumber * decNumberCopySign(decNumber *, const decNumber *, const decNumber *);
159 decNumber * decNumberNextMinus(decNumber *, const decNumber *, decContext *);
160 decNumber * decNumberNextPlus(decNumber *, const decNumber *, decContext *);
161 decNumber * decNumberNextToward(decNumber *, const decNumber *, const decNumber *, decContext *);
162 decNumber * decNumberTrim(decNumber *);
163 const char * decNumberVersion(void);
164 decNumber * decNumberZero(decNumber *);
165
166
167 int32_t decNumberIsNormal(const decNumber *, decContext *);
168 int32_t decNumberIsSubnormal(const decNumber *, decContext *);
169
170
171 # define decNumberIsCanonical(dn) (1)
172 # define decNumberIsFinite(dn) (((dn)->bits&DECSPECIAL)==0)
173 # define decNumberIsInfinite(dn) (((dn)->bits&DECINF)!=0)
174 # define decNumberIsNaN(dn) (((dn)->bits&(DECNAN|DECSNAN))!=0)
175 # define decNumberIsNegative(dn) (((dn)->bits&DECNEG)!=0)
176 # define decNumberIsQNaN(dn) (((dn)->bits&(DECNAN))!=0)
177 # define decNumberIsSNaN(dn) (((dn)->bits&(DECSNAN))!=0)
178 # define decNumberIsSpecial(dn) (((dn)->bits&DECSPECIAL)!=0)
179 # define decNumberIsZero(dn) (*(dn)->lsu==0 \
180 && (dn)->digits==1 \
181 && (((dn)->bits&DECSPECIAL)==0))
182 # define decNumberRadix(dn) (10)
183
184 #endif