1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #if !defined(DECNUMBERLOC)
32 # define DECNUMBERLOC
33 # define DECVERSION "decNumber 3.68"
34 # define DECVERSEXT "20210520p4"
35 # define DECNLAUTHOR "Mike Cowlishaw"
36
37 # include <stdlib.h>
38 # include <string.h>
39
40 # if !defined(_MSC_VER)
41 # include <sys/param.h>
42 # endif
43
44 # include <sys/types.h>
45
46 # if defined(__linux__) || defined(__CYGWIN__) || \
47 defined(__GNU__) || defined(__GLIBC__) || \
48 defined(__HAIKU__)
49 # include <endian.h>
50 # if !defined(LITTLE_ENDIAN) && defined(__LITTLE_ENDIAN)
51 # define LITTLE_ENDIAN __LITTLE_ENDIAN
52 # endif
53 # if !defined(BIG_ENDIAN) && defined(__BIG_ENDIAN)
54 # define BIG_ENDIAN __BIG_ENDIAN
55 # endif
56 # if !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
57 # define BYTE_ORDER __BYTE_ORDER
58 # endif
59 # endif
60
61 # if defined(__sun)
62 # include <sys/byteorder.h>
63 # define LITTLE_ENDIAN 1234
64 # define BIG_ENDIAN 4321
65 # if defined(_BIG_ENDIAN)
66 # define BYTE_ORDER BIG_ENDIAN
67 # elif defined(_LITTLE_ENDIAN)
68 # define BYTE_ORDER LITTLE_ENDIAN
69 # else
70 # error "Cannot determine endian-ness of this Sun system."
71 # endif
72 # endif
73
74 # if defined(_AIX) && !defined(BYTE_ORDER)
75 # define LITTLE_ENDIAN 1234
76 # define BIG_ENDIAN 4321
77 # if defined(__BIG_ENDIAN__)
78 # define BYTE_ORDER BIG_ENDIAN
79 # elif defined(__LITTLE_ENDIAN__)
80 # define BYTE_ORDER LITTLE_ENDIAN
81 # else
82 # error "Cannot determine endian-ness of this IBM AIX system."
83 # endif
84 # endif
85
86 # if defined(_WIN32)
87 # define LITTLE_ENDIAN 1234
88 # define BIG_ENDIAN 4321
89 # define BYTE_ORDER LITTLE_ENDIAN
90 # endif
91
92 # if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
93 # error "Cannot determine the endian-ness of this platform."
94 # endif
95
96 # if BYTE_ORDER == LITTLE_ENDIAN
97 # define DECLITEND 1
98 # elif BYTE_ORDER == BIG_ENDIAN
99 # define DECLITEND 0
100 # endif
101
102
103 # if !defined(DECUSE64)
104 # define DECUSE64 1
105 # endif
106
107
108 # if !defined(DECBUFFER)
109 # define DECBUFFER 36
110
111
112
113 # endif
114
115
116
117
118
119
120
121 # define Flag uint8_t
122 # define Byte int8_t
123 # define uByte uint8_t
124 # define Short int16_t
125 # define uShort uint16_t
126 # define Int int32_t
127 # define uInt uint32_t
128 # define Unit decNumberUnit
129 # if DECUSE64
130 # define Long int64_t
131 # define uLong uint64_t
132 # endif
133
134
135 # define DECNOINT 0
136
137 # if DECNOINT
138
139 # define int ?
140 # define long ??
141 # endif
142
143
144 extern const uByte DECSTICKYTAB[10];
145 extern const uInt DECPOWERS[10];
146
147 extern const uShort DPD2BIN[1024];
148 extern const uShort BIN2DPD[1000];
149 extern const uInt DPD2BINK[1024];
150 extern const uInt DPD2BINM[1024];
151 extern const uByte DPD2BCD8[4096];
152 extern const uByte BIN2BCD8[4000];
153 extern const uShort BCD2DPD[2458];
154
155
156
157
158
159
160 # define LONGMUL32HI(w, u, v) { \
161 uInt u0, u1, v0, v1, w0, w1, w2, t; \
162 u0=u & 0xffff; u1=u>>16; \
163 v0=v & 0xffff; v1=v>>16; \
164 w0=u0*v0; \
165 t=u1*v0 + (w0>>16); \
166 w1=t & 0xffff; w2=t>>16; \
167 w1=u0*v1 + w1; \
168 (w)=u1*v1 + w2 + (w1>>16);}
169
170
171 # define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n)
172 # define ROUNDUP4(i) (((i)+3)&~3)
173
174
175 # define ROUNDDOWN(i, n) (((i)/n)*n)
176 # define ROUNDDOWN4(i) ((i)&~3)
177
178
179
180
181
182
183
184
185 # define UBTOUS(b) (memcpy((void *)&uswork, b, 2), uswork)
186 # define UBTOUI(b) (memcpy((void *)&uiwork, b, 4), uiwork)
187
188
189 # define UBFROMUS(b, i) (uswork=(i), memcpy(b, (void *)&uswork, 2))
190 # define UBFROMUI(b, i) (uiwork=(i), memcpy(b, (void *)&uiwork, 4))
191
192
193
194 # define X10(i) (((i)<<1)+((i)<<3))
195 # define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
196
197
198 # define MAXI(x,y) ((x)<(y)?(y):(x))
199 # define MINI(x,y) ((x)>(y)?(y):(x))
200
201
202 # define BILLION 1000000000
203
204 # define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0')
205
206
207
208
209
210
211
212 # define DECNUMMAXP 999999999
213 # define DECNUMMAXE 999999999
214 # define DECNUMMINE -999999999
215 # if (DECNUMMAXP != DEC_MAX_DIGITS)
216 # error Maximum digits mismatch
217 # endif
218 # if (DECNUMMAXE != DEC_MAX_EMAX)
219 # error Maximum exponent mismatch
220 # endif
221 # if (DECNUMMINE != DEC_MIN_EMIN)
222 # error Minimum exponent mismatch
223 # endif
224
225
226
227 # if DECDPUN==1
228 # define DECDPUNMAX 9
229 # define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, \
230 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \
231 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \
232 48,49}
233 # elif DECDPUN==2
234 # define DECDPUNMAX 99
235 # define D2UTABLE {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10, \
236 11,11,12,12,13,13,14,14,15,15,16,16,17,17,18, \
237 18,19,19,20,20,21,21,22,22,23,23,24,24,25}
238 # elif DECDPUN==3
239 # define DECDPUNMAX 999
240 # define D2UTABLE {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7, \
241 8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13, \
242 13,14,14,14,15,15,15,16,16,16,17}
243 # elif DECDPUN==4
244 # define DECDPUNMAX 9999
245 # define D2UTABLE {0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6, \
246 6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11, \
247 11,11,11,12,12,12,12,13}
248 # elif DECDPUN==5
249 # define DECDPUNMAX 99999
250 # define D2UTABLE {0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5, \
251 5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9, \
252 9,9,10,10,10,10}
253 # elif DECDPUN==6
254 # define DECDPUNMAX 999999
255 # define D2UTABLE {0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4, \
256 4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8, \
257 8,8,8,8,8,9}
258 # elif DECDPUN==7
259 # define DECDPUNMAX 9999999
260 # define D2UTABLE {0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3, \
261 4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7, \
262 7,7,7,7,7,7}
263 # elif DECDPUN==8
264 # define DECDPUNMAX 99999999
265 # define D2UTABLE {0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3, \
266 3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6, \
267 6,6,6,6,6,7}
268 # elif DECDPUN==9
269 # define DECDPUNMAX 999999999
270 # define D2UTABLE {0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3, \
271 3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5, \
272 5,5,6,6,6,6}
273 # elif defined(DECDPUN)
274 # error DECDPUN must be in the range 1-9
275 # endif
276
277
278
279 # define DECMAXD2U 49
280 extern const uByte d2utable[DECMAXD2U+1];
281
282
283
284
285 # define ISZERO(dn) decNumberIsZero(dn)
286
287
288
289 # if DECDPUN==8
290 # define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+7)>>3))
291 # elif DECDPUN==4
292 # define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+3)>>2))
293 # else
294 # define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
295 # endif
296
297 # define SD2U(d) (((d)+DECDPUN-1)/DECDPUN)
298
299
300
301 # define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
302
303
304
305
306
307
308 # define D2N(d) \
309 ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber))
310
311
312
313
314
315
316
317
318 # define TODIGIT(u, cut, c, pow) { \
319 *(c)='0'; \
320 pow=DECPOWERS[cut]*2; \
321 if ((u)>pow) { \
322 pow*=4; \
323 if ((u)>=pow) {(u)-=pow; *(c)+=8;} \
324 pow/=2; \
325 if ((u)>=pow) {(u)-=pow; *(c)+=4;} \
326 pow/=2; \
327 } \
328 if ((u)>=pow) {(u)-=pow; *(c)+=2;} \
329 pow/=2; \
330 if ((u)>=pow) {(u)-=pow; *(c)+=1;} \
331 }
332
333
334
335
336
337
338
339
340 typedef struct {
341 uByte *msd;
342 uByte *lsd;
343 uInt sign;
344 Int exponent;
345
346 } bcdnum;
347
348
349 # define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp)
350 # define EXPISINF(exp) (exp==DECFLOAT_Inf)
351 # define EXPISNAN(exp) (exp==DECFLOAT_qNaN || exp==DECFLOAT_sNaN)
352 # define NUMISSPECIAL(num) (EXPISSPECIAL((num)->exponent))
353
354
355
356
357
358 # define DECWORDS (DECBYTES/4)
359 # define DECWWORDS (DECWBYTES/4)
360 # if DECLITEND
361 # define DFBYTE(df, off) ((df)->bytes[DECBYTES-1-(off)])
362 # define DFWORD(df, off) ((df)->words[DECWORDS-1-(off)])
363 # define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)])
364 # else
365 # define DFBYTE(df, off) ((df)->bytes[off])
366 # define DFWORD(df, off) ((df)->words[off])
367 # define DFWWORD(dfw, off) ((dfw)->words[off])
368 # endif
369
370
371 # define DFISSIGNED(df) ((DFWORD(df, 0)&0x80000000)!=0)
372 # define DFISSPECIAL(df) ((DFWORD(df, 0)&0x78000000)==0x78000000)
373 # define DFISINF(df) ((DFWORD(df, 0)&0x7c000000)==0x78000000)
374 # define DFISNAN(df) ((DFWORD(df, 0)&0x7c000000)==0x7c000000)
375 # define DFISQNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7c000000)
376 # define DFISSNAN(df) ((DFWORD(df, 0)&0x7e000000)==0x7e000000)
377
378
379 extern const uInt DECCOMBMSD[64];
380 extern const uInt DECCOMBFROM[48];
381
382
383 # if defined(DECPMAX)
384
385
386 # define DECPMAX9 (ROUNDUP(DECPMAX, 9)/9)
387
388 # define SINGLEZERO 0x22500000
389 # define DOUBLEZERO 0x22380000
390 # define QUADZERO 0x22080000
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408 # if DECPMAX==7
409 # define ZEROWORD SINGLEZERO
410
411 # define DFISZERO(df) ((DFWORD(df, 0)&0x1c0fffff)==0 \
412 && (DFWORD(df, 0)&0x60000000)!=0x60000000)
413 # elif DECPMAX==16
414 # define ZEROWORD DOUBLEZERO
415 # define DFISZERO(df) ((DFWORD(df, 1)==0 \
416 && (DFWORD(df, 0)&0x1c03ffff)==0 \
417 && (DFWORD(df, 0)&0x60000000)!=0x60000000))
418 # define DFISINT(df) ((DFWORD(df, 0)&0x63fc0000)==0x22380000 \
419 ||(DFWORD(df, 0)&0x7bfc0000)==0x6a380000)
420 # define DFISUINT01(df) ((DFWORD(df, 0)&0xfbfc0000)==0x22380000)
421 # define DFISCCZERO(df) (DFWORD(df, 1)==0 \
422 && (DFWORD(df, 0)&0x0003ffff)==0)
423 # define DFISCC01(df) ((DFWORD(df, 0)&~0xfffc9124)==0 \
424 && (DFWORD(df, 1)&~0x49124491)==0)
425 # elif DECPMAX==34
426 # define ZEROWORD QUADZERO
427 # define DFISZERO(df) ((DFWORD(df, 3)==0 \
428 && DFWORD(df, 2)==0 \
429 && DFWORD(df, 1)==0 \
430 && (DFWORD(df, 0)&0x1c003fff)==0 \
431 && (DFWORD(df, 0)&0x60000000)!=0x60000000))
432 # define DFISINT(df) ((DFWORD(df, 0)&0x63ffc000)==0x22080000 \
433 ||(DFWORD(df, 0)&0x7bffc000)==0x6a080000)
434 # define DFISUINT01(df) ((DFWORD(df, 0)&0xfbffc000)==0x22080000)
435 # define DFISCCZERO(df) (DFWORD(df, 3)==0 \
436 && DFWORD(df, 2)==0 \
437 && DFWORD(df, 1)==0 \
438 && (DFWORD(df, 0)&0x00003fff)==0)
439
440 # define DFISCC01(df) ((DFWORD(df, 0)&~0xffffc912)==0 \
441 && (DFWORD(df, 1)&~0x44912449)==0 \
442 && (DFWORD(df, 2)&~0x12449124)==0 \
443 && (DFWORD(df, 3)&~0x49124491)==0)
444 # endif
445
446
447
448
449 # define CANONDPD(dpd) (((dpd)&0x300)==0 || ((dpd)&0x6e)!=0x6e)
450
451 # define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0 \
452 || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
453
454
455 # define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0 \
456 || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k))) \
457 || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
458
459
460
461
462
463 # if DECPMAX==7
464 # define ISCOEFFZERO(u) ( \
465 UBTOUI((u)+DECPMAX-4)==0 \
466 && UBTOUS((u)+DECPMAX-6)==0 \
467 && *(u)==0)
468 # elif DECPMAX==16
469 # define ISCOEFFZERO(u) ( \
470 UBTOUI((u)+DECPMAX-4)==0 \
471 && UBTOUI((u)+DECPMAX-8)==0 \
472 && UBTOUI((u)+DECPMAX-12)==0 \
473 && UBTOUI(u)==0)
474 # elif DECPMAX==34
475 # define ISCOEFFZERO(u) ( \
476 UBTOUI((u)+DECPMAX-4)==0 \
477 && UBTOUI((u)+DECPMAX-8)==0 \
478 && UBTOUI((u)+DECPMAX-12)==0 \
479 && UBTOUI((u)+DECPMAX-16)==0 \
480 && UBTOUI((u)+DECPMAX-20)==0 \
481 && UBTOUI((u)+DECPMAX-24)==0 \
482 && UBTOUI((u)+DECPMAX-28)==0 \
483 && UBTOUI((u)+DECPMAX-32)==0 \
484 && UBTOUS(u)==0)
485 # endif
486
487
488
489 # define GETSIGN(df) (DFWORD(df, 0)&0x80000000)
490
491 # define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL)))
492
493 # define GETWECON(df) ((Int)((DFWWORD((df), 0)&0x03ffffff)>>(32-6-DECWECONL)))
494
495 # define GETEXP(df) ((Int)(DECCOMBEXP[DFWORD((df), 0)>>26]+GETECON(df)))
496
497 # define GETEXPUN(df) ((Int)GETEXP(df)-DECBIAS)
498
499 # define GETMSD(df) (DECCOMBMSD[DFWORD((df), 0)>>26])
500
501
502
503 # define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
504
505 # define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
506
507
508
509
510
511
512
513
514
515 # define dpd2bcd8(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 4)
516 # define dpd2bcd83(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 3)
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532 # if DECPMAX==7
533 # define GETCOEFF(df, bcd) { \
534 uInt sourhi=DFWORD(df, 0); \
535 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
536 dpd2bcd8(bcd+1, sourhi>>10); \
537 dpd2bcd83(bcd+4, sourhi);}
538 # define GETWCOEFF(df, bcd) { \
539 uInt sourhi=DFWWORD(df, 0); \
540 uInt sourlo=DFWWORD(df, 1); \
541 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
542 dpd2bcd8(bcd+1, sourhi>>8); \
543 dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
544 dpd2bcd8(bcd+7, sourlo>>20); \
545 dpd2bcd8(bcd+10, sourlo>>10); \
546 dpd2bcd83(bcd+13, sourlo);}
547
548 # elif DECPMAX==16
549 # define GETCOEFF(df, bcd) { \
550 uInt sourhi=DFWORD(df, 0); \
551 uInt sourlo=DFWORD(df, 1); \
552 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
553 dpd2bcd8(bcd+1, sourhi>>8); \
554 dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30)); \
555 dpd2bcd8(bcd+7, sourlo>>20); \
556 dpd2bcd8(bcd+10, sourlo>>10); \
557 dpd2bcd83(bcd+13, sourlo);}
558 # define GETWCOEFF(df, bcd) { \
559 uInt sourhi=DFWWORD(df, 0); \
560 uInt sourmh=DFWWORD(df, 1); \
561 uInt sourml=DFWWORD(df, 2); \
562 uInt sourlo=DFWWORD(df, 3); \
563 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
564 dpd2bcd8(bcd+1, sourhi>>4); \
565 dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
566 dpd2bcd8(bcd+7, sourmh>>16); \
567 dpd2bcd8(bcd+10, sourmh>>6); \
568 dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
569 dpd2bcd8(bcd+16, sourml>>18); \
570 dpd2bcd8(bcd+19, sourml>>8); \
571 dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
572 dpd2bcd8(bcd+25, sourlo>>20); \
573 dpd2bcd8(bcd+28, sourlo>>10); \
574 dpd2bcd83(bcd+31, sourlo);}
575
576 # elif DECPMAX==34
577 # define GETCOEFF(df, bcd) { \
578 uInt sourhi=DFWORD(df, 0); \
579 uInt sourmh=DFWORD(df, 1); \
580 uInt sourml=DFWORD(df, 2); \
581 uInt sourlo=DFWORD(df, 3); \
582 *(bcd)=(uByte)DECCOMBMSD[sourhi>>26]; \
583 dpd2bcd8(bcd+1, sourhi>>4); \
584 dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26)); \
585 dpd2bcd8(bcd+7, sourmh>>16); \
586 dpd2bcd8(bcd+10, sourmh>>6); \
587 dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28)); \
588 dpd2bcd8(bcd+16, sourml>>18); \
589 dpd2bcd8(bcd+19, sourml>>8); \
590 dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30)); \
591 dpd2bcd8(bcd+25, sourlo>>20); \
592 dpd2bcd8(bcd+28, sourlo>>10); \
593 dpd2bcd83(bcd+31, sourlo);}
594
595 # define GETWCOEFF(df, bcd) {??}
596 # endif
597
598
599
600
601
602
603
604
605
606
607
608 # define DPD2BIN0 DPD2BIN
609
610 # if DECPMAX==7
611 # define GETCOEFFBILL(df, buf) { \
612 uInt sourhi=DFWORD(df, 0); \
613 (buf)[0]=DPD2BIN0[sourhi&0x3ff] \
614 +DPD2BINK[(sourhi>>10)&0x3ff] \
615 +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
616
617 # elif DECPMAX==16
618 # define GETCOEFFBILL(df, buf) { \
619 uInt sourhi, sourlo; \
620 sourlo=DFWORD(df, 1); \
621 (buf)[0]=DPD2BIN0[sourlo&0x3ff] \
622 +DPD2BINK[(sourlo>>10)&0x3ff] \
623 +DPD2BINM[(sourlo>>20)&0x3ff]; \
624 sourhi=DFWORD(df, 0); \
625 (buf)[1]=DPD2BIN0[((sourhi<<2) | (sourlo>>30))&0x3ff] \
626 +DPD2BINK[(sourhi>>8)&0x3ff] \
627 +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
628
629 # elif DECPMAX==34
630 # define GETCOEFFBILL(df, buf) { \
631 uInt sourhi, sourmh, sourml, sourlo; \
632 sourlo=DFWORD(df, 3); \
633 (buf)[0]=DPD2BIN0[sourlo&0x3ff] \
634 +DPD2BINK[(sourlo>>10)&0x3ff] \
635 +DPD2BINM[(sourlo>>20)&0x3ff]; \
636 sourml=DFWORD(df, 2); \
637 (buf)[1]=DPD2BIN0[((sourml<<2) | (sourlo>>30))&0x3ff] \
638 +DPD2BINK[(sourml>>8)&0x3ff] \
639 +DPD2BINM[(sourml>>18)&0x3ff]; \
640 sourmh=DFWORD(df, 1); \
641 (buf)[2]=DPD2BIN0[((sourmh<<4) | (sourml>>28))&0x3ff] \
642 +DPD2BINK[(sourmh>>6)&0x3ff] \
643 +DPD2BINM[(sourmh>>16)&0x3ff]; \
644 sourhi=DFWORD(df, 0); \
645 (buf)[3]=DPD2BIN0[((sourhi<<6) | (sourmh>>26))&0x3ff] \
646 +DPD2BINK[(sourhi>>4)&0x3ff] \
647 +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
648
649 # endif
650
651
652
653
654
655
656
657 # if DECPMAX==7
658 # define GETCOEFFTHOU(df, buf) { \
659 uInt sourhi=DFWORD(df, 0); \
660 (buf)[0]=DPD2BIN[sourhi&0x3ff]; \
661 (buf)[1]=DPD2BIN[(sourhi>>10)&0x3ff]; \
662 (buf)[2]=DECCOMBMSD[sourhi>>26];}
663
664 # elif DECPMAX==16
665 # define GETCOEFFTHOU(df, buf) { \
666 uInt sourhi, sourlo; \
667 sourlo=DFWORD(df, 1); \
668 (buf)[0]=DPD2BIN[sourlo&0x3ff]; \
669 (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
670 (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
671 sourhi=DFWORD(df, 0); \
672 (buf)[3]=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
673 (buf)[4]=DPD2BIN[(sourhi>>8)&0x3ff]; \
674 (buf)[5]=DECCOMBMSD[sourhi>>26];}
675
676 # elif DECPMAX==34
677 # define GETCOEFFTHOU(df, buf) { \
678 uInt sourhi, sourmh, sourml, sourlo; \
679 sourlo=DFWORD(df, 3); \
680 (buf)[0]=DPD2BIN[sourlo&0x3ff]; \
681 (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff]; \
682 (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff]; \
683 sourml=DFWORD(df, 2); \
684 (buf)[3]=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
685 (buf)[4]=DPD2BIN[(sourml>>8)&0x3ff]; \
686 (buf)[5]=DPD2BIN[(sourml>>18)&0x3ff]; \
687 sourmh=DFWORD(df, 1); \
688 (buf)[6]=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
689 (buf)[7]=DPD2BIN[(sourmh>>6)&0x3ff]; \
690 (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff]; \
691 sourhi=DFWORD(df, 0); \
692 (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
693 (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff]; \
694 (buf)[11]=DECCOMBMSD[sourhi>>26];}
695 # endif
696
697
698
699
700
701 # if DECPMAX==7
702 # define ADDCOEFFTHOU(df, buf) { \
703 uInt sourhi=DFWORD(df, 0); \
704 (buf)[0]+=DPD2BIN[sourhi&0x3ff]; \
705 if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
706 (buf)[1]+=DPD2BIN[(sourhi>>10)&0x3ff]; \
707 if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
708 (buf)[2]+=DECCOMBMSD[sourhi>>26];}
709
710 # elif DECPMAX==16
711 # define ADDCOEFFTHOU(df, buf) { \
712 uInt sourhi, sourlo; \
713 sourlo=DFWORD(df, 1); \
714 (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \
715 if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
716 (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \
717 if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
718 (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \
719 if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \
720 sourhi=DFWORD(df, 0); \
721 (buf)[3]+=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff]; \
722 if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \
723 (buf)[4]+=DPD2BIN[(sourhi>>8)&0x3ff]; \
724 if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \
725 (buf)[5]+=DECCOMBMSD[sourhi>>26];}
726
727 # elif DECPMAX==34
728 # define ADDCOEFFTHOU(df, buf) { \
729 uInt sourhi, sourmh, sourml, sourlo; \
730 sourlo=DFWORD(df, 3); \
731 (buf)[0]+=DPD2BIN[sourlo&0x3ff]; \
732 if (buf[0]>999) {buf[0]-=1000; buf[1]++;} \
733 (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff]; \
734 if (buf[1]>999) {buf[1]-=1000; buf[2]++;} \
735 (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff]; \
736 if (buf[2]>999) {buf[2]-=1000; buf[3]++;} \
737 sourml=DFWORD(df, 2); \
738 (buf)[3]+=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff]; \
739 if (buf[3]>999) {buf[3]-=1000; buf[4]++;} \
740 (buf)[4]+=DPD2BIN[(sourml>>8)&0x3ff]; \
741 if (buf[4]>999) {buf[4]-=1000; buf[5]++;} \
742 (buf)[5]+=DPD2BIN[(sourml>>18)&0x3ff]; \
743 if (buf[5]>999) {buf[5]-=1000; buf[6]++;} \
744 sourmh=DFWORD(df, 1); \
745 (buf)[6]+=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff]; \
746 if (buf[6]>999) {buf[6]-=1000; buf[7]++;} \
747 (buf)[7]+=DPD2BIN[(sourmh>>6)&0x3ff]; \
748 if (buf[7]>999) {buf[7]-=1000; buf[8]++;} \
749 (buf)[8]+=DPD2BIN[(sourmh>>16)&0x3ff]; \
750 if (buf[8]>999) {buf[8]-=1000; buf[9]++;} \
751 sourhi=DFWORD(df, 0); \
752 (buf)[9]+=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff]; \
753 if (buf[9]>999) {buf[9]-=1000; buf[10]++;} \
754 (buf)[10]+=DPD2BIN[(sourhi>>4)&0x3ff]; \
755 if (buf[10]>999) {buf[10]-=1000; buf[11]++;} \
756 (buf)[11]+=DECCOMBMSD[sourhi>>26];}
757 # endif
758
759
760 # if DECPMAX==7
761 # define DFSETNMAX(df) \
762 {DFWORD(df, 0)=0x77f3fcff;}
763 # elif DECPMAX==16
764 # define DFSETNMAX(df) \
765 {DFWORD(df, 0)=0x77fcff3f; \
766 DFWORD(df, 1)=0xcff3fcff;}
767 # elif DECPMAX==34
768 # define DFSETNMAX(df) \
769 {DFWORD(df, 0)=0x77ffcff3; \
770 DFWORD(df, 1)=0xfcff3fcf; \
771 DFWORD(df, 2)=0xf3fcff3f; \
772 DFWORD(df, 3)=0xcff3fcff;}
773 # endif
774
775
776 # endif
777
778 #else
779 # error decNumberLocal included more than once
780 #endif