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