decNumberLocal.h revision 1.1 1 1.1 mrg /* Local definitions for the decNumber C Library.
2 1.1 mrg Copyright (C) 2007, 2009 Free Software Foundation, Inc.
3 1.1 mrg Contributed by IBM Corporation. Author Mike Cowlishaw.
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
8 1.1 mrg the terms of the GNU General Public License as published by the Free
9 1.1 mrg Software Foundation; either version 3, or (at your option) any later
10 1.1 mrg version.
11 1.1 mrg
12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 1.1 mrg for more details.
16 1.1 mrg
17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional
18 1.1 mrg permissions described in the GCC Runtime Library Exception, version
19 1.1 mrg 3.1, as published by the Free Software Foundation.
20 1.1 mrg
21 1.1 mrg You should have received a copy of the GNU General Public License and
22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program;
23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 1.1 mrg <http://www.gnu.org/licenses/>. */
25 1.1 mrg
26 1.1 mrg /* ------------------------------------------------------------------ */
27 1.1 mrg /* decNumber package local type, tuning, and macro definitions */
28 1.1 mrg /* ------------------------------------------------------------------ */
29 1.1 mrg /* This header file is included by all modules in the decNumber */
30 1.1 mrg /* library, and contains local type definitions, tuning parameters, */
31 1.1 mrg /* etc. It should not need to be used by application programs. */
32 1.1 mrg /* decNumber.h or one of decDouble (etc.) must be included first. */
33 1.1 mrg /* ------------------------------------------------------------------ */
34 1.1 mrg
35 1.1 mrg #if !defined(DECNUMBERLOC)
36 1.1 mrg #define DECNUMBERLOC
37 1.1 mrg #define DECVERSION "decNumber 3.61" /* Package Version [16 max.] */
38 1.1 mrg #define DECNLAUTHOR "Mike Cowlishaw" /* Who to blame */
39 1.1 mrg
40 1.1 mrg #include <stdlib.h> /* for abs */
41 1.1 mrg #include <string.h> /* for memset, strcpy */
42 1.1 mrg #include "dconfig.h" /* for WORDS_BIGENDIAN */
43 1.1 mrg
44 1.1 mrg /* Conditional code flag -- set this to match hardware platform */
45 1.1 mrg /* 1=little-endian, 0=big-endian */
46 1.1 mrg #if WORDS_BIGENDIAN
47 1.1 mrg #define DECLITEND 0
48 1.1 mrg #else
49 1.1 mrg #define DECLITEND 1
50 1.1 mrg #endif
51 1.1 mrg
52 1.1 mrg #if !defined(DECLITEND)
53 1.1 mrg #define DECLITEND 1 /* 1=little-endian, 0=big-endian */
54 1.1 mrg #endif
55 1.1 mrg
56 1.1 mrg /* Conditional code flag -- set this to 1 for best performance */
57 1.1 mrg #if !defined(DECUSE64)
58 1.1 mrg #define DECUSE64 1 /* 1=use int64s, 0=int32 & smaller only */
59 1.1 mrg #endif
60 1.1 mrg
61 1.1 mrg /* Conditional check flags -- set these to 0 for best performance */
62 1.1 mrg #if !defined(DECCHECK)
63 1.1 mrg #define DECCHECK 0 /* 1 to enable robust checking */
64 1.1 mrg #endif
65 1.1 mrg #if !defined(DECALLOC)
66 1.1 mrg #define DECALLOC 0 /* 1 to enable memory accounting */
67 1.1 mrg #endif
68 1.1 mrg #if !defined(DECTRACE)
69 1.1 mrg #define DECTRACE 0 /* 1 to trace certain internals, etc. */
70 1.1 mrg #endif
71 1.1 mrg
72 1.1 mrg /* Tuning parameter for decNumber (arbitrary precision) module */
73 1.1 mrg #if !defined(DECBUFFER)
74 1.1 mrg #define DECBUFFER 36 /* Size basis for local buffers. This */
75 1.1 mrg /* should be a common maximum precision */
76 1.1 mrg /* rounded up to a multiple of 4; must */
77 1.1 mrg /* be zero or positive. */
78 1.1 mrg #endif
79 1.1 mrg
80 1.1 mrg /* ---------------------------------------------------------------- */
81 1.1 mrg /* Definitions for all modules (general-purpose) */
82 1.1 mrg /* ---------------------------------------------------------------- */
83 1.1 mrg
84 1.1 mrg /* Local names for common types -- for safety, decNumber modules do */
85 1.1 mrg /* not use int or long directly. */
86 1.1 mrg #define Flag uint8_t
87 1.1 mrg #define Byte int8_t
88 1.1 mrg #define uByte uint8_t
89 1.1 mrg #define Short int16_t
90 1.1 mrg #define uShort uint16_t
91 1.1 mrg #define Int int32_t
92 1.1 mrg #define uInt uint32_t
93 1.1 mrg #define Unit decNumberUnit
94 1.1 mrg #if DECUSE64
95 1.1 mrg #define Long int64_t
96 1.1 mrg #define uLong uint64_t
97 1.1 mrg #endif
98 1.1 mrg
99 1.1 mrg /* Development-use definitions */
100 1.1 mrg typedef long int LI; /* for printf arguments only */
101 1.1 mrg #define DECNOINT 0 /* 1 to check no internal use of 'int' */
102 1.1 mrg /* or stdint types */
103 1.1 mrg #if DECNOINT
104 1.1 mrg /* if these interfere with your C includes, do not set DECNOINT */
105 1.1 mrg #define int ? /* enable to ensure that plain C 'int' */
106 1.1 mrg #define long ?? /* .. or 'long' types are not used */
107 1.1 mrg #endif
108 1.1 mrg
109 1.1 mrg /* Shared lookup tables */
110 1.1 mrg extern const uByte DECSTICKYTAB[10]; /* re-round digits if sticky */
111 1.1 mrg extern const uInt DECPOWERS[10]; /* powers of ten table */
112 1.1 mrg /* The following are included from decDPD.h */
113 1.1 mrg #include "decDPDSymbols.h"
114 1.1 mrg extern const uShort DPD2BIN[1024]; /* DPD -> 0-999 */
115 1.1 mrg extern const uShort BIN2DPD[1000]; /* 0-999 -> DPD */
116 1.1 mrg extern const uInt DPD2BINK[1024]; /* DPD -> 0-999000 */
117 1.1 mrg extern const uInt DPD2BINM[1024]; /* DPD -> 0-999000000 */
118 1.1 mrg extern const uByte DPD2BCD8[4096]; /* DPD -> ddd + len */
119 1.1 mrg extern const uByte BIN2BCD8[4000]; /* 0-999 -> ddd + len */
120 1.1 mrg extern const uShort BCD2DPD[2458]; /* 0-0x999 -> DPD (0x999=2457)*/
121 1.1 mrg
122 1.1 mrg /* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts */
123 1.1 mrg /* (that is, sets w to be the high-order word of the 64-bit result; */
124 1.1 mrg /* the low-order word is simply u*v.) */
125 1.1 mrg /* This version is derived from Knuth via Hacker's Delight; */
126 1.1 mrg /* it seems to optimize better than some others tried */
127 1.1 mrg #define LONGMUL32HI(w, u, v) { \
128 1.1 mrg uInt u0, u1, v0, v1, w0, w1, w2, t; \
129 1.1 mrg u0=u & 0xffff; u1=u>>16; \
130 1.1 mrg v0=v & 0xffff; v1=v>>16; \
131 1.1 mrg w0=u0*v0; \
132 1.1 mrg t=u1*v0 + (w0>>16); \
133 1.1 mrg w1=t & 0xffff; w2=t>>16; \
134 1.1 mrg w1=u0*v1 + w1; \
135 1.1 mrg (w)=u1*v1 + w2 + (w1>>16);}
136 1.1 mrg
137 1.1 mrg /* ROUNDUP -- round an integer up to a multiple of n */
138 1.1 mrg #define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n)
139 1.1 mrg #define ROUNDUP4(i) (((i)+3)&~3) /* special for n=4 */
140 1.1 mrg
141 1.1 mrg /* ROUNDDOWN -- round an integer down to a multiple of n */
142 1.1 mrg #define ROUNDDOWN(i, n) (((i)/n)*n)
143 1.1 mrg #define ROUNDDOWN4(i) ((i)&~3) /* special for n=4 */
144 1.1 mrg
145 1.1 mrg /* References to multi-byte sequences under different sizes; these */
146 1.1 mrg /* require locally declared variables, but do not violate strict */
147 1.1 mrg /* aliasing or alignment (as did the UINTAT simple cast to uInt). */
148 1.1 mrg /* Variables needed are uswork, uiwork, etc. [so do not use at same */
149 1.1 mrg /* level in an expression, e.g., UBTOUI(x)==UBTOUI(y) may fail]. */
150 1.1 mrg
151 1.1 mrg /* Return a uInt, etc., from bytes starting at a char* or uByte* */
152 1.1 mrg #define UBTOUS(b) (memcpy((void *)&uswork, b, 2), uswork)
153 1.1 mrg #define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork)
154 1.1 mrg
155 1.1 mrg /* Store a uInt, etc., into bytes starting at a char* or uByte*. */
156 1.1 mrg /* Returns i, evaluated, for convenience; has to use uiwork because */
157 1.1 mrg /* i may be an expression. */
158 1.1 mrg #define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2), uswork)
159 1.1 mrg #define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4), uiwork)
160 1.1 mrg
161 1.1 mrg /* X10 and X100 -- multiply integer i by 10 or 100 */
162 1.1 mrg /* [shifts are usually faster than multiply; could be conditional] */
163 1.1 mrg #define X10(i) (((i)<<1)+((i)<<3))
164 1.1 mrg #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
165 1.1 mrg
166 1.1 mrg /* MAXI and MINI -- general max & min (not in ANSI) for integers */
167 1.1 mrg #define MAXI(x,y) ((x)<(y)?(y):(x))
168 1.1 mrg #define MINI(x,y) ((x)>(y)?(y):(x))
169 1.1 mrg
170 1.1 mrg /* Useful constants */
171 1.1 mrg #define BILLION 1000000000 /* 10**9 */
172 1.1 mrg /* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC */
173 1.1 mrg #define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0')
174 1.1 mrg
175 1.1 mrg
176 1.1 mrg /* ---------------------------------------------------------------- */
177 1.1 mrg /* Definitions for arbitary-precision modules (only valid after */
178 1.1 mrg /* decNumber.h has been included) */
179 1.1 mrg /* ---------------------------------------------------------------- */
180 1.1 mrg
181 1.1 mrg /* Limits and constants */
182 1.1 mrg #define DECNUMMAXP 999999999 /* maximum precision code can handle */
183 1.1 mrg #define DECNUMMAXE 999999999 /* maximum adjusted exponent ditto */
184 1.1 mrg #define DECNUMMINE -999999999 /* minimum adjusted exponent ditto */
185 1.1 mrg #if (DECNUMMAXP != DEC_MAX_DIGITS)
186 1.1 mrg #error Maximum digits mismatch
187 1.1 mrg #endif
188 1.1 mrg #if (DECNUMMAXE != DEC_MAX_EMAX)
189 1.1 mrg #error Maximum exponent mismatch
190 1.1 mrg #endif
191 1.1 mrg #if (DECNUMMINE != DEC_MIN_EMIN)
192 1.1 mrg #error Minimum exponent mismatch
193 1.1 mrg #endif
194 1.1 mrg
195 1.1 mrg /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN */
196 1.1 mrg /* digits, and D2UTABLE -- the initializer for the D2U table */
197 1.1 mrg #if DECDPUN==1
198 1.1 mrg #define DECDPUNMAX 9
199 1.1 mrg #define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, \
200 1.1 mrg 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \
201 1.1 mrg 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \
202 1.1 mrg 48,49}
203 1.1 mrg #elif DECDPUN==2
204 1.1 mrg #define DECDPUNMAX 99
205 1.1 mrg #define D2UTABLE {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10, \
206 1.1 mrg 11,11,12,12,13,13,14,14,15,15,16,16,17,17,18, \
207 1.1 mrg 18,19,19,20,20,21,21,22,22,23,23,24,24,25}
208 1.1 mrg #elif DECDPUN==3
209 1.1 mrg #define DECDPUNMAX 999
210 1.1 mrg #define D2UTABLE {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, \
211 1.1 mrg 8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13, \
212 1.1 mrg 13,14,14,14,15,15,15,16,16,16,17}
213 1.1 mrg #elif DECDPUN==4
214 1.1 mrg #define DECDPUNMAX 9999
215 1.1 mrg #define D2UTABLE {0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6, \
216 1.1 mrg 6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11, \
217 1.1 mrg 11,11,11,12,12,12,12,13}
218 1.1 mrg #elif DECDPUN==5
219 1.1 mrg #define DECDPUNMAX 99999
220 1.1 mrg #define D2UTABLE {0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5, \
221 1.1 mrg 5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9, \
222 1.1 mrg 9,9,10,10,10,10}
223 1.1 mrg #elif DECDPUN==6
224 1.1 mrg #define DECDPUNMAX 999999
225 1.1 mrg #define D2UTABLE {0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4, \
226 1.1 mrg 4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8, \
227 1.1 mrg 8,8,8,8,8,9}
228 1.1 mrg #elif DECDPUN==7
229 1.1 mrg #define DECDPUNMAX 9999999
230 1.1 mrg #define D2UTABLE {0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3, \
231 1.1 mrg 4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7, \
232 1.1 mrg 7,7,7,7,7,7}
233 1.1 mrg #elif DECDPUN==8
234 1.1 mrg #define DECDPUNMAX 99999999
235 1.1 mrg #define D2UTABLE {0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3, \
236 1.1 mrg 3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6, \
237 1.1 mrg 6,6,6,6,6,7}
238 1.1 mrg #elif DECDPUN==9
239 1.1 mrg #define DECDPUNMAX 999999999
240 1.1 mrg #define D2UTABLE {0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3, \
241 1.1 mrg 3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5, \
242 1.1 mrg 5,5,6,6,6,6}
243 1.1 mrg #elif defined(DECDPUN)
244 1.1 mrg #error DECDPUN must be in the range 1-9
245 1.1 mrg #endif
246 1.1 mrg
247 1.1 mrg /* ----- Shared data (in decNumber.c) ----- */
248 1.1 mrg /* Public lookup table used by the D2U macro (see below) */
249 1.1 mrg #define DECMAXD2U 49
250 1.1 mrg extern const uByte d2utable[DECMAXD2U+1];
251 1.1 mrg
252 1.1 mrg /* ----- Macros ----- */
253 1.1 mrg /* ISZERO -- return true if decNumber dn is a zero */
254 1.1 mrg /* [performance-critical in some situations] */
255 1.1 mrg #define ISZERO(dn) decNumberIsZero(dn) /* now just a local name */
256 1.1 mrg
257 1.1 mrg /* D2U -- return the number of Units needed to hold d digits */
258 1.1 mrg /* (runtime version, with table lookaside for small d) */
259 1.1 mrg #if DECDPUN==8
260 1.1 mrg #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+7)>>3))
261 1.1 mrg #elif DECDPUN==4
262 1.1 mrg #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+3)>>2))
263 1.1 mrg #else
264 1.1 mrg #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
265 1.1 mrg #endif
266 1.1 mrg /* SD2U -- static D2U macro (for compile-time calculation) */
267 1.1 mrg #define SD2U(d) (((d)+DECDPUN-1)/DECDPUN)
268 1.1 mrg
269 1.1 mrg /* MSUDIGITS -- returns digits in msu, from digits, calculated */
270 1.1 mrg /* using D2U */
271 1.1 mrg #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
272 1.1 mrg
273 1.1 mrg /* D2N -- return the number of decNumber structs that would be */
274 1.1 mrg /* needed to contain that number of digits (and the initial */
275 1.1 mrg /* decNumber struct) safely. Note that one Unit is included in the */
276 1.1 mrg /* initial structure. Used for allocating space that is aligned on */
277 1.1 mrg /* a decNumber struct boundary. */
278 1.1 mrg #define D2N(d) \
279 1.1 mrg ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber))
280 1.1 mrg
281 1.1 mrg /* TODIGIT -- macro to remove the leading digit from the unsigned */
282 1.1 mrg /* integer u at column cut (counting from the right, LSD=0) and */
283 1.1 mrg /* place it as an ASCII character into the character pointed to by */
284 1.1 mrg /* c. Note that cut must be <= 9, and the maximum value for u is */
285 1.1 mrg /* 2,000,000,000 (as is needed for negative exponents of */
286 1.1 mrg /* subnormals). The unsigned integer pow is used as a temporary */
287 1.1 mrg /* variable. */
288 1.1 mrg #define TODIGIT(u, cut, c, pow) { \
289 1.1 mrg *(c)='0'; \
290 1.1 mrg pow=DECPOWERS[cut]*2; \
291 1.1 mrg if ((u)>pow) { \
292 1.1 mrg pow*=4; \
293 1.1 mrg if ((u)>=pow) {(u)-=pow; *(c)+=8;} \
294 1.1 mrg pow/=2; \
295 1.1 mrg if ((u)>=pow) {(u)-=pow; *(c)+=4;} \
296 1.1 mrg pow/=2; \
297 1.1 mrg } \
298 1.1 mrg if ((u)>=pow) {(u)-=pow; *(c)+=2;} \
299 1.1 mrg pow/=2; \
300 1.1 mrg if ((u)>=pow) {(u)-=pow; *(c)+=1;} \
301 1.1 mrg }
302 1.1 mrg
303 1.1 mrg /* ---------------------------------------------------------------- */
304 1.1 mrg /* Definitions for fixed-precision modules (only valid after */
305 1.1 mrg /* decSingle.h, decDouble.h, or decQuad.h has been included) */
306 1.1 mrg /* ---------------------------------------------------------------- */
307 1.1 mrg
308 1.1 mrg /* bcdnum -- a structure describing a format-independent finite */
309 1.1 mrg /* number, whose coefficient is a string of bcd8 uBytes */
310 1.1 mrg typedef struct {
311 1.1 mrg uByte *msd; /* -> most significant digit */
312 1.1 mrg uByte *lsd; /* -> least ditto */
313 1.1 mrg uInt sign; /* 0=positive, DECFLOAT_Sign=negative */
314 1.1 mrg Int exponent; /* Unadjusted signed exponent (q), or */
315 1.1 mrg /* DECFLOAT_NaN etc. for a special */
316 1.1 mrg } bcdnum;
317 1.1 mrg
318 1.1 mrg /* Test if exponent or bcdnum exponent must be a special, etc. */
319 1.1 mrg #define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp)
320 1.1 mrg #define EXPISINF(exp) (exp==DECFLOAT_Inf)
321 1.1 mrg #define EXPISNAN(exp) (exp==DECFLOAT_qNaN || exp==DECFLOAT_sNaN)
322 1.1 mrg #define NUMISSPECIAL(num) (EXPISSPECIAL((num)->exponent))
323 1.1 mrg
324 1.1 mrg /* Refer to a 32-bit word or byte in a decFloat (df) by big-endian */
325 1.1 mrg /* (array) notation (the 0 word or byte contains the sign bit), */
326 1.1 mrg /* automatically adjusting for endianness; similarly address a word */
327 1.1 mrg /* in the next-wider format (decFloatWider, or dfw) */
328 1.1 mrg #define DECWORDS (DECBYTES/4)
329 1.1 mrg #define DECWWORDS (DECWBYTES/4)
330 1.1 mrg #if DECLITEND
331 1.1 mrg #define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)])
332 1.1 mrg #define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)])
333 1.1 mrg #define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)])
334 1.1 mrg #else
335 1.1 mrg #define DFBYTE(df, off) ((df)->bytes[off])
336 1.1 mrg #define DFWORD(df, off) ((df)->words[off])
337 1.1 mrg #define DFWWORD(dfw, off) ((dfw)->words[off])
338 1.1 mrg #endif
339 1.1 mrg
340 1.1 mrg /* Tests for sign or specials, directly on DECFLOATs */
341 1.1 mrg #define DFISSIGNED(df) (DFWORD(df, 0)&0x80000000)
342 1.1 mrg #define DFISSPECIAL(df) ((DFWORD(df, 0)&0x78000000)==0x78000000)
343 1.1 mrg #define DFISINF(df) ((DFWORD(df, 0)&0x7c000000)==0x78000000)
344 1.1 mrg #define DFISNAN(df) ((DFWORD(df, 0)&0x7c000000)==0x7c000000)
345 1.1 mrg #define DFISQNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7c000000)
346 1.1 mrg #define DFISSNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7e000000)
347 1.1 mrg
348 1.1 mrg /* Shared lookup tables */
349 1.1 mrg #include "decCommonSymbols.h"
350 1.1 mrg extern const uInt DECCOMBMSD[64]; /* Combination field -> MSD */
351 1.1 mrg extern const uInt DECCOMBFROM[48]; /* exp+msd -> Combination */
352 1.1 mrg
353 1.1 mrg /* Private generic (utility) routine */
354 1.1 mrg #if DECCHECK || DECTRACE
355 1.1 mrg extern void decShowNum(const bcdnum *, const char *);
356 1.1 mrg #endif
357 1.1 mrg
358 1.1 mrg /* Format-dependent macros and constants */
359 1.1 mrg #if defined(DECPMAX)
360 1.1 mrg
361 1.1 mrg /* Useful constants */
362 1.1 mrg #define DECPMAX9 (ROUNDUP(DECPMAX, 9)/9) /* 'Pmax' in 10**9s */
363 1.1 mrg /* Top words for a zero */
364 1.1 mrg #define SINGLEZERO 0x22500000
365 1.1 mrg #define DOUBLEZERO 0x22380000
366 1.1 mrg #define QUADZERO 0x22080000
367 1.1 mrg /* [ZEROWORD is defined to be one of these in the DFISZERO macro] */
368 1.1 mrg
369 1.1 mrg /* Format-dependent common tests: */
370 1.1 mrg /* DFISZERO -- test for (any) zero */
371 1.1 mrg /* DFISCCZERO -- test for coefficient continuation being zero */
372 1.1 mrg /* DFISCC01 -- test for coefficient contains only 0s and 1s */
373 1.1 mrg /* DFISINT -- test for finite and exponent q=0 */
374 1.1 mrg /* DFISUINT01 -- test for sign=0, finite, exponent q=0, and */
375 1.1 mrg /* MSD=0 or 1 */
376 1.1 mrg /* ZEROWORD is also defined here. */
377 1.1 mrg /* In DFISZERO the first test checks the least-significant word */
378 1.1 mrg /* (most likely to be non-zero); the penultimate tests MSD and */
379 1.1 mrg /* DPDs in the signword, and the final test excludes specials and */
380 1.1 mrg /* MSD>7. DFISINT similarly has to allow for the two forms of */
381 1.1 mrg /* MSD codes. DFISUINT01 only has to allow for one form of MSD */
382 1.1 mrg /* code. */
383 1.1 mrg #if DECPMAX==7
384 1.1 mrg #define ZEROWORD SINGLEZERO
385 1.1 mrg /* [test macros not needed except for Zero] */
386 1.1 mrg #define DFISZERO(df) ((DFWORD(df, 0)&0x1c0fffff)==0 \
387 1.1 mrg && (DFWORD(df, 0)&0x60000000)!=0x60000000)
388 1.1 mrg #elif DECPMAX==16
389 1.1 mrg #define ZEROWORD DOUBLEZERO
390 1.1 mrg #define DFISZERO(df) ((DFWORD(df, 1)==0 \
391 1.1 mrg && (DFWORD(df, 0)&0x1c03ffff)==0 \
392 1.1 mrg && (DFWORD(df, 0)&0x60000000)!=0x60000000))
393 1.1 mrg #define DFISINT(df) ((DFWORD(df, 0)&0x63fc0000)==0x22380000 \
394 1.1 mrg ||(DFWORD(df, 0)&0x7bfc0000)==0x6a380000)
395 1.1 mrg #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbfc0000)==0x22380000)
396 1.1 mrg #define DFISCCZERO(df) (DFWORD(df, 1)==0 \
397 1.1 mrg && (DFWORD(df, 0)&0x0003ffff)==0)
398 1.1 mrg #define DFISCC01(df) ((DFWORD(df, 0)&~0xfffc9124)==0 \
399 1.1 mrg && (DFWORD(df, 1)&~0x49124491)==0)
400 1.1 mrg #elif DECPMAX==34
401 1.1 mrg #define ZEROWORD QUADZERO
402 1.1 mrg #define DFISZERO(df) ((DFWORD(df, 3)==0 \
403 1.1 mrg && DFWORD(df, 2)==0 \
404 1.1 mrg && DFWORD(df, 1)==0 \
405 1.1 mrg && (DFWORD(df, 0)&0x1c003fff)==0 \
406 1.1 mrg && (DFWORD(df, 0)&0x60000000)!=0x60000000))
407 1.1 mrg #define DFISINT(df) ((DFWORD(df, 0)&0x63ffc000)==0x22080000 \
408 1.1 mrg ||(DFWORD(df, 0)&0x7bffc000)==0x6a080000)
409 1.1 mrg #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbffc000)==0x22080000)
410 1.1 mrg #define DFISCCZERO(df) (DFWORD(df, 3)==0 \
411 1.1 mrg && DFWORD(df, 2)==0 \
412 1.1 mrg && DFWORD(df, 1)==0 \
413 1.1 mrg && (DFWORD(df, 0)&0x00003fff)==0)
414 1.1 mrg
415 1.1 mrg #define DFISCC01(df) ((DFWORD(df, 0)&~0xffffc912)==0 \
416 1.1 mrg && (DFWORD(df, 1)&~0x44912449)==0 \
417 1.1 mrg && (DFWORD(df, 2)&~0x12449124)==0 \
418 1.1 mrg && (DFWORD(df, 3)&~0x49124491)==0)
419 1.1 mrg #endif
420 1.1 mrg
421 1.1 mrg /* Macros to test if a certain 10 bits of a uInt or pair of uInts */
422 1.1 mrg /* are a canonical declet [higher or lower bits are ignored]. */
423 1.1 mrg /* declet is at offset 0 (from the right) in a uInt: */
424 1.1 mrg #define CANONDPD(dpd) (((dpd)&0x300)==0 || ((dpd)&0x6e)!=0x6e)
425 1.1 mrg /* declet is at offset k (a multiple of 2) in a uInt: */
426 1.1 mrg #define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0 \
427 1.1 mrg || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
428 1.1 mrg /* declet is at offset k (a multiple of 2) in a pair of uInts: */
429 1.1 mrg /* [the top 2 bits will always be in the more-significant uInt] */
430 1.1 mrg #define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0 \
431 1.1 mrg || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k))) \
432 1.1 mrg || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
433 1.1 mrg
434 1.1 mrg /* Macro to test whether a full-length (length DECPMAX) BCD8 */
435 1.1 mrg /* coefficient, starting at uByte u, is all zeros */
436 1.1 mrg /* Test just the LSWord first, then the remainder as a sequence */
437 1.1 mrg /* of tests in order to avoid same-level use of UBTOUI */
438 1.1 mrg #if DECPMAX==7
439 1.1 mrg #define ISCOEFFZERO(u) ( \
440 1.1 mrg UBTOUI((u)+DECPMAX-4)==0 \
441 1.1 mrg && UBTOUS((u)+DECPMAX-6)==0 \
442 1.1 mrg && *(u)==0)
443 1.1 mrg #elif DECPMAX==16
444 1.1 mrg #define ISCOEFFZERO(u) ( \
445 1.1 mrg UBTOUI((u)+DECPMAX-4)==0 \
446 1.1 mrg && UBTOUI((u)+DECPMAX-8)==0 \
447 1.1 mrg && UBTOUI((u)+DECPMAX-12)==0 \
448 1.1 mrg && UBTOUI(u)==0)
449 1.1 mrg #elif DECPMAX==34
450 1.1 mrg #define ISCOEFFZERO(u) ( \
451 1.1 mrg UBTOUI((u)+DECPMAX-4)==0 \
452 1.1 mrg && UBTOUI((u)+DECPMAX-8)==0 \
453 1.1 mrg && UBTOUI((u)+DECPMAX-12)==0 \
454 1.1 mrg && UBTOUI((u)+DECPMAX-16)==0 \
455 1.1 mrg && UBTOUI((u)+DECPMAX-20)==0 \
456 1.1 mrg && UBTOUI((u)+DECPMAX-24)==0 \
457 1.1 mrg && UBTOUI((u)+DECPMAX-28)==0 \
458 1.1 mrg && UBTOUI((u)+DECPMAX-32)==0 \
459 1.1 mrg && UBTOUS(u)==0)
460 1.1 mrg #endif
461 1.1 mrg
462 1.1 mrg /* Macros and masks for the exponent continuation field and MSD */
463 1.1 mrg /* Get the exponent continuation from a decFloat *df as an Int */
464 1.1 mrg #define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL)))
465 1.1 mrg /* Ditto, from the next-wider format */
466 1.1 mrg #define GETWECON(df) ((Int)((DFWWORD((df), 0)&0x03ffffff)>>(32-6-DECWECONL)))
467 1.1 mrg /* Get the biased exponent similarly */
468 1.1 mrg #define GETEXP(df) ((Int)(DECCOMBEXP[DFWORD((df), 0)>>26]+GETECON(df)))
469 1.1 mrg /* Get the unbiased exponent similarly */
470 1.1 mrg #define GETEXPUN(df) ((Int)GETEXP(df)-DECBIAS)
471 1.1 mrg /* Get the MSD similarly (as uInt) */
472 1.1 mrg #define GETMSD(df) (DECCOMBMSD[DFWORD((df), 0)>>26])
473 1.1 mrg
474 1.1 mrg /* Compile-time computes of the exponent continuation field masks */
475 1.1 mrg /* full exponent continuation field: */
476 1.1 mrg #define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
477 1.1 mrg /* same, not including its first digit (the qNaN/sNaN selector): */
478 1.1 mrg #define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
479 1.1 mrg
480 1.1 mrg /* Macros to decode the coefficient in a finite decFloat *df into */
481 1.1 mrg /* a BCD string (uByte *bcdin) of length DECPMAX uBytes. */
482 1.1 mrg
483 1.1 mrg /* In-line sequence to convert least significant 10 bits of uInt */
484 1.1 mrg /* dpd to three BCD8 digits starting at uByte u. Note that an */
485 1.1 mrg /* extra byte is written to the right of the three digits because */
486 1.1 mrg /* four bytes are moved at a time for speed; the alternative */
487 1.1 mrg /* macro moves exactly three bytes (usually slower). */
488 1.1 mrg #define dpd2bcd8(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 4)
489 1.1 mrg #define dpd2bcd83(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 3)
490 1.1 mrg
491 1.1 mrg /* Decode the declets. After extracting each one, it is decoded */
492 1.1 mrg /* to BCD8 using a table lookup (also used for variable-length */
493 1.1 mrg /* decode). Each DPD decode is 3 bytes BCD8 plus a one-byte */
494 1.1 mrg /* length which is not used, here). Fixed-length 4-byte moves */
495 1.1 mrg /* are fast, however, almost everywhere, and so are used except */
496 1.1 mrg /* for the final three bytes (to avoid overrun). The code below */
497 1.1 mrg /* is 36 instructions for Doubles and about 70 for Quads, even */
498 1.1 mrg /* on IA32. */
499 1.1 mrg
500 1.1 mrg /* Two macros are defined for each format: */
501 1.1 mrg /* GETCOEFF extracts the coefficient of the current format */
502 1.1 mrg /* GETWCOEFF extracts the coefficient of the next-wider format. */
503 1.1 mrg /* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */
504 1.1 mrg
505 1.1 mrg #if DECPMAX==7
506 1.1 mrg #define GETCOEFF(df, bcd) { \
507 1.1 mrg uInt sourhi=DFWORD(df, 0); \
508 1.1 mrg *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
509 1.1 mrg dpd2bcd8(bcd+1, sourhi>>10); \
510 1.1 mrg dpd2bcd83(bcd+4, sourhi);}
511 1.1 mrg #define GETWCOEFF(df, bcd) { \
512 1.1 mrg uInt sourhi=DFWWORD(df, 0); \
513 1.1 mrg uInt sourlo=DFWWORD(df, 1); \
514 1.1 mrg *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
515 1.1 mrg dpd2bcd8(bcd+1, sourhi>>8); \
516 1.1 mrg dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
517 1.1 mrg dpd2bcd8(bcd+7, sourlo>>20); \
518 1.1 mrg dpd2bcd8(bcd+10, sourlo>>10); \
519 1.1 mrg dpd2bcd83(bcd+13, sourlo);}
520 1.1 mrg
521 1.1 mrg #elif DECPMAX==16
522 1.1 mrg #define GETCOEFF(df, bcd) { \
523 1.1 mrg uInt sourhi=DFWORD(df, 0); \
524 1.1 mrg uInt sourlo=DFWORD(df, 1); \
525 1.1 mrg *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
526 1.1 mrg dpd2bcd8(bcd+1, sourhi>>8); \
527 1.1 mrg dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
528 1.1 mrg dpd2bcd8(bcd+7, sourlo>>20); \
529 1.1 mrg dpd2bcd8(bcd+10, sourlo>>10); \
530 1.1 mrg dpd2bcd83(bcd+13, sourlo);}
531 1.1 mrg #define GETWCOEFF(df, bcd) { \
532 1.1 mrg uInt sourhi=DFWWORD(df, 0); \
533 1.1 mrg uInt sourmh=DFWWORD(df, 1); \
534 1.1 mrg uInt sourml=DFWWORD(df, 2); \
535 1.1 mrg uInt sourlo=DFWWORD(df, 3); \
536 1.1 mrg *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
537 1.1 mrg dpd2bcd8(bcd+1, sourhi>>4); \
538 1.1 mrg dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
539 1.1 mrg dpd2bcd8(bcd+7, sourmh>>16); \
540 1.1 mrg dpd2bcd8(bcd+10, sourmh>>6); \
541 1.1 mrg dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
542 1.1 mrg dpd2bcd8(bcd+16, sourml>>18); \
543 1.1 mrg dpd2bcd8(bcd+19, sourml>>8); \
544 1.1 mrg dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
545 1.1 mrg dpd2bcd8(bcd+25, sourlo>>20); \
546 1.1 mrg dpd2bcd8(bcd+28, sourlo>>10); \
547 1.1 mrg dpd2bcd83(bcd+31, sourlo);}
548 1.1 mrg
549 1.1 mrg #elif DECPMAX==34
550 1.1 mrg #define GETCOEFF(df, bcd) { \
551 1.1 mrg uInt sourhi=DFWORD(df, 0); \
552 1.1 mrg uInt sourmh=DFWORD(df, 1); \
553 1.1 mrg uInt sourml=DFWORD(df, 2); \
554 1.1 mrg uInt sourlo=DFWORD(df, 3); \
555 1.1 mrg *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
556 1.1 mrg dpd2bcd8(bcd+1, sourhi>>4); \
557 1.1 mrg dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
558 1.1 mrg dpd2bcd8(bcd+7, sourmh>>16); \
559 1.1 mrg dpd2bcd8(bcd+10, sourmh>>6); \
560 1.1 mrg dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
561 1.1 mrg dpd2bcd8(bcd+16, sourml>>18); \
562 1.1 mrg dpd2bcd8(bcd+19, sourml>>8); \
563 1.1 mrg dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
564 1.1 mrg dpd2bcd8(bcd+25, sourlo>>20); \
565 1.1 mrg dpd2bcd8(bcd+28, sourlo>>10); \
566 1.1 mrg dpd2bcd83(bcd+31, sourlo);}
567 1.1 mrg
568 1.1 mrg #define GETWCOEFF(df, bcd) {??} /* [should never be used] */
569 1.1 mrg #endif
570 1.1 mrg
571 1.1 mrg /* Macros to decode the coefficient in a finite decFloat *df into */
572 1.1 mrg /* a base-billion uInt array, with the least-significant */
573 1.1 mrg /* 0-999999999 'digit' at offset 0. */
574 1.1 mrg
575 1.1 mrg /* Decode the declets. After extracting each one, it is decoded */
576 1.1 mrg /* to binary using a table lookup. Three tables are used; one */
577 1.1 mrg /* the usual DPD to binary, the other two pre-multiplied by 1000 */
578 1.1 mrg /* and 1000000 to avoid multiplication during decode. These */
579 1.1 mrg /* tables can also be used for multiplying up the MSD as the DPD */
580 1.1 mrg /* code for 0 through 9 is the identity. */
581 1.1 mrg #define DPD2BIN0 DPD2BIN /* for prettier code */
582 1.1 mrg
583 1.1 mrg #if DECPMAX==7
584 1.1 mrg #define GETCOEFFBILL(df, buf) { \
585 1.1 mrg uInt sourhi=DFWORD(df, 0); \
586 1.1 mrg (buf)[0]=DPD2BIN0[sourhi&0x3ff] \
587 1.1 mrg +DPD2BINK[(sourhi>>10)&0x3ff] \
588 1.1 mrg +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
589 1.1 mrg
590 1.1 mrg #elif DECPMAX==16
591 1.1 mrg #define GETCOEFFBILL(df, buf) { \
592 1.1 mrg uInt sourhi, sourlo; \
593 1.1 mrg sourlo=DFWORD(df, 1); \
594 1.1 mrg (buf)[0]=DPD2BIN0[sourlo&0x3ff] \
595 1.1 mrg +DPD2BINK[(sourlo>>10)&0x3ff] \
596 1.1 mrg +DPD2BINM[(sourlo>>20)&0x3ff]; \
597 1.1 mrg sourhi=DFWORD(df, 0); \
598 1.1 mrg (buf)[1]=DPD2BIN0[((sourhi<<2) | (sourlo>>30))&0x3ff] \
599 1.1 mrg +DPD2BINK[(sourhi>>8)&0x3ff] \
600 1.1 mrg +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
601 1.1 mrg
602 1.1 mrg #elif DECPMAX==34
603 1.1 mrg #define GETCOEFFBILL(df, buf) { \
604 1.1 mrg uInt sourhi, sourmh, sourml, sourlo; \
605 1.1 mrg sourlo=DFWORD(df, 3); \
606 1.1 mrg (buf)[0]=DPD2BIN0[sourlo&0x3ff] \
607 1.1 mrg +DPD2BINK[(sourlo>>10)&0x3ff] \
608 1.1 mrg +DPD2BINM[(sourlo>>20)&0x3ff]; \
609 1.1 mrg sourml=DFWORD(df, 2); \
610 1.1 mrg (buf)[1]=DPD2BIN0[((sourml<<2) | (sourlo>>30))&0x3ff] \
611 1.1 mrg +DPD2BINK[(sourml>>8)&0x3ff] \
612 1.1 mrg +DPD2BINM[(sourml>>18)&0x3ff]; \
613 1.1 mrg sourmh=DFWORD(df, 1); \
614 1.1 mrg (buf)[2]=DPD2BIN0[((sourmh<<4) | (sourml>>28))&0x3ff] \
615 1.1 mrg +DPD2BINK[(sourmh>>6)&0x3ff] \
616 1.1 mrg +DPD2BINM[(sourmh>>16)&0x3ff]; \
617 1.1 mrg sourhi=DFWORD(df, 0); \
618 1.1 mrg (buf)[3]=DPD2BIN0[((sourhi<<6) | (sourmh>>26))&0x3ff] \
619 1.1 mrg +DPD2BINK[(sourhi>>4)&0x3ff] \
620 1.1 mrg +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
621 1.1 mrg
622 1.1 mrg #endif
623 1.1 mrg
624 1.1 mrg /* Macros to decode the coefficient in a finite decFloat *df into */
625 1.1 mrg /* a base-thousand uInt array (of size DECLETS+1, to allow for */
626 1.1 mrg /* the MSD), with the least-significant 0-999 'digit' at offset 0.*/
627 1.1 mrg
628 1.1 mrg /* Decode the declets. After extracting each one, it is decoded */
629 1.1 mrg /* to binary using a table lookup. */
630 1.1 mrg #if DECPMAX==7
631 1.1 mrg #define GETCOEFFTHOU(df, buf) { \
632 1.1 mrg uInt sourhi=DFWORD(df, 0); \
633 1.1 mrg (buf)[0]=DPD2BIN[sourhi&0x3ff]; \
634 1.1 mrg (buf)[1]=DPD2BIN[(sourhi>>10)&0x3ff]; \
635 1.1 mrg (buf)[2]=DECCOMBMSD[sourhi>>26];}
636 1.1 mrg
637 1.1 mrg #elif DECPMAX==16
638 1.1 mrg #define GETCOEFFTHOU(df, buf) { \
639 1.1 mrg uInt sourhi, sourlo; \
640 1.1 mrg sourlo=DFWORD(df, 1); \
641 1.1 mrg (buf)[0]=DPD2BIN[sourlo&0x3ff]; \
642 1.1 mrg (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
643 1.1 mrg (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
644 1.1 mrg sourhi=DFWORD(df, 0); \
645 1.1 mrg (buf)[3]=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
646 1.1 mrg (buf)[4]=DPD2BIN[(sourhi>>8)&0x3ff]; \
647 1.1 mrg (buf)[5]=DECCOMBMSD[sourhi>>26];}
648 1.1 mrg
649 1.1 mrg #elif DECPMAX==34
650 1.1 mrg #define GETCOEFFTHOU(df, buf) { \
651 1.1 mrg uInt sourhi, sourmh, sourml, sourlo; \
652 1.1 mrg sourlo=DFWORD(df, 3); \
653 1.1 mrg (buf)[0]=DPD2BIN[sourlo&0x3ff]; \
654 1.1 mrg (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
655 1.1 mrg (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
656 1.1 mrg sourml=DFWORD(df, 2); \
657 1.1 mrg (buf)[3]=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
658 1.1 mrg (buf)[4]=DPD2BIN[(sourml>>8)&0x3ff]; \
659 1.1 mrg (buf)[5]=DPD2BIN[(sourml>>18)&0x3ff]; \
660 1.1 mrg sourmh=DFWORD(df, 1); \
661 1.1 mrg (buf)[6]=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
662 1.1 mrg (buf)[7]=DPD2BIN[(sourmh>>6)&0x3ff]; \
663 1.1 mrg (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff]; \
664 1.1 mrg sourhi=DFWORD(df, 0); \
665 1.1 mrg (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
666 1.1 mrg (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff]; \
667 1.1 mrg (buf)[11]=DECCOMBMSD[sourhi>>26];}
668 1.1 mrg #endif
669 1.1 mrg
670 1.1 mrg
671 1.1 mrg /* Macros to decode the coefficient in a finite decFloat *df and */
672 1.1 mrg /* add to a base-thousand uInt array (as for GETCOEFFTHOU). */
673 1.1 mrg /* After the addition then most significant 'digit' in the array */
674 1.1 mrg /* might have a value larger then 10 (with a maximum of 19). */
675 1.1 mrg #if DECPMAX==7
676 1.1 mrg #define ADDCOEFFTHOU(df, buf) { \
677 1.1 mrg uInt sourhi=DFWORD(df, 0); \
678 1.1 mrg (buf)[0]+=DPD2BIN[sourhi&0x3ff]; \
679 1.1 mrg if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
680 1.1 mrg (buf)[1]+=DPD2BIN[(sourhi>>10)&0x3ff]; \
681 1.1 mrg if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
682 1.1 mrg (buf)[2]+=DECCOMBMSD[sourhi>>26];}
683 1.1 mrg
684 1.1 mrg #elif DECPMAX==16
685 1.1 mrg #define ADDCOEFFTHOU(df, buf) { \
686 1.1 mrg uInt sourhi, sourlo; \
687 1.1 mrg sourlo=DFWORD(df, 1); \
688 1.1 mrg (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \
689 1.1 mrg if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
690 1.1 mrg (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \
691 1.1 mrg if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
692 1.1 mrg (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \
693 1.1 mrg if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \
694 1.1 mrg sourhi=DFWORD(df, 0); \
695 1.1 mrg (buf)[3]+=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
696 1.1 mrg if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \
697 1.1 mrg (buf)[4]+=DPD2BIN[(sourhi>>8)&0x3ff]; \
698 1.1 mrg if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \
699 1.1 mrg (buf)[5]+=DECCOMBMSD[sourhi>>26];}
700 1.1 mrg
701 1.1 mrg #elif DECPMAX==34
702 1.1 mrg #define ADDCOEFFTHOU(df, buf) { \
703 1.1 mrg uInt sourhi, sourmh, sourml, sourlo; \
704 1.1 mrg sourlo=DFWORD(df, 3); \
705 1.1 mrg (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \
706 1.1 mrg if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
707 1.1 mrg (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \
708 1.1 mrg if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
709 1.1 mrg (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \
710 1.1 mrg if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \
711 1.1 mrg sourml=DFWORD(df, 2); \
712 1.1 mrg (buf)[3]+=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
713 1.1 mrg if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \
714 1.1 mrg (buf)[4]+=DPD2BIN[(sourml>>8)&0x3ff]; \
715 1.1 mrg if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \
716 1.1 mrg (buf)[5]+=DPD2BIN[(sourml>>18)&0x3ff]; \
717 1.1 mrg if (buf[5]>999) {buf[5]-=1000; buf[6]++;} \
718 1.1 mrg sourmh=DFWORD(df, 1); \
719 1.1 mrg (buf)[6]+=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
720 1.1 mrg if (buf[6]>999) {buf[6]-=1000; buf[7]++;} \
721 1.1 mrg (buf)[7]+=DPD2BIN[(sourmh>>6)&0x3ff]; \
722 1.1 mrg if (buf[7]>999) {buf[7]-=1000; buf[8]++;} \
723 1.1 mrg (buf)[8]+=DPD2BIN[(sourmh>>16)&0x3ff]; \
724 1.1 mrg if (buf[8]>999) {buf[8]-=1000; buf[9]++;} \
725 1.1 mrg sourhi=DFWORD(df, 0); \
726 1.1 mrg (buf)[9]+=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
727 1.1 mrg if (buf[9]>999) {buf[9]-=1000; buf[10]++;} \
728 1.1 mrg (buf)[10]+=DPD2BIN[(sourhi>>4)&0x3ff]; \
729 1.1 mrg if (buf[10]>999) {buf[10]-=1000; buf[11]++;} \
730 1.1 mrg (buf)[11]+=DECCOMBMSD[sourhi>>26];}
731 1.1 mrg #endif
732 1.1 mrg
733 1.1 mrg
734 1.1 mrg /* Set a decFloat to the maximum positive finite number (Nmax) */
735 1.1 mrg #if DECPMAX==7
736 1.1 mrg #define DFSETNMAX(df) \
737 1.1 mrg {DFWORD(df, 0)=0x77f3fcff;}
738 1.1 mrg #elif DECPMAX==16
739 1.1 mrg #define DFSETNMAX(df) \
740 1.1 mrg {DFWORD(df, 0)=0x77fcff3f; \
741 1.1 mrg DFWORD(df, 1)=0xcff3fcff;}
742 1.1 mrg #elif DECPMAX==34
743 1.1 mrg #define DFSETNMAX(df) \
744 1.1 mrg {DFWORD(df, 0)=0x77ffcff3; \
745 1.1 mrg DFWORD(df, 1)=0xfcff3fcf; \
746 1.1 mrg DFWORD(df, 2)=0xf3fcff3f; \
747 1.1 mrg DFWORD(df, 3)=0xcff3fcff;}
748 1.1 mrg #endif
749 1.1 mrg
750 1.1 mrg /* [end of format-dependent macros and constants] */
751 1.1 mrg #endif
752 1.1 mrg
753 1.1 mrg #else
754 1.1 mrg #error decNumberLocal included more than once
755 1.1 mrg #endif
756