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