Blame libdecnumber/decNumberLocal.h

Packit Service 706eca
/* Local definitions for the decNumber C Library.
Packit Service 706eca
   Copyright (C) 2007-2018 Free Software Foundation, Inc.
Packit Service 706eca
   Contributed by IBM Corporation.  Author Mike Cowlishaw.
Packit Service 706eca
Packit Service 706eca
   This file is part of GCC.
Packit Service 706eca
Packit Service 706eca
   GCC is free software; you can redistribute it and/or modify it under
Packit Service 706eca
   the terms of the GNU General Public License as published by the Free
Packit Service 706eca
   Software Foundation; either version 3, or (at your option) any later
Packit Service 706eca
   version.
Packit Service 706eca
Packit Service 706eca
   GCC is distributed in the hope that it will be useful, but WITHOUT ANY
Packit Service 706eca
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit Service 706eca
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit Service 706eca
   for more details.
Packit Service 706eca
Packit Service 706eca
Under Section 7 of GPL version 3, you are granted additional
Packit Service 706eca
permissions described in the GCC Runtime Library Exception, version
Packit Service 706eca
3.1, as published by the Free Software Foundation.
Packit Service 706eca
Packit Service 706eca
You should have received a copy of the GNU General Public License and
Packit Service 706eca
a copy of the GCC Runtime Library Exception along with this program;
Packit Service 706eca
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
Packit Service 706eca
<http://www.gnu.org/licenses/>.  */
Packit Service 706eca
Packit Service 706eca
/* ------------------------------------------------------------------ */
Packit Service 706eca
/* decNumber package local type, tuning, and macro definitions	      */
Packit Service 706eca
/* ------------------------------------------------------------------ */
Packit Service 706eca
/* This header file is included by all modules in the decNumber       */
Packit Service 706eca
/* library, and contains local type definitions, tuning parameters,   */
Packit Service 706eca
/* etc.  It should not need to be used by application programs.       */
Packit Service 706eca
/* decNumber.h or one of decDouble (etc.) must be included first.     */
Packit Service 706eca
/* ------------------------------------------------------------------ */
Packit Service 706eca
Packit Service 706eca
#if !defined(DECNUMBERLOC)
Packit Service 706eca
  #define DECNUMBERLOC
Packit Service 706eca
  #define DECVERSION	"decNumber 3.61" /* Package Version [16 max.] */
Packit Service 706eca
  #define DECNLAUTHOR	"Mike Cowlishaw"	      /* Who to blame */
Packit Service 706eca
Packit Service 706eca
  #include <stdlib.h>	      /* for abs			      */
Packit Service 706eca
  #include <string.h>	      /* for memset, strcpy		      */
Packit Service 706eca
  #include "dconfig.h"        /* for WORDS_BIGENDIAN		      */
Packit Service 706eca
Packit Service 706eca
  /* Conditional code flag -- set this to match hardware platform     */
Packit Service 706eca
  /* 1=little-endian, 0=big-endian                                   */
Packit Service 706eca
  #if WORDS_BIGENDIAN
Packit Service 706eca
  #define DECLITEND 0
Packit Service 706eca
  #else
Packit Service 706eca
  #define DECLITEND 1
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  #if !defined(DECLITEND)
Packit Service 706eca
  #define DECLITEND 1	      /* 1=little-endian, 0=big-endian	      */
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Conditional code flag -- set this to 1 for best performance      */
Packit Service 706eca
  #if !defined(DECUSE64)
Packit Service 706eca
  #define DECUSE64  1	      /* 1=use int64s, 0=int32 & smaller only */
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Conditional check flags -- set these to 0 for best performance   */
Packit Service 706eca
  #if !defined(DECCHECK)
Packit Service 706eca
  #define DECCHECK  0	      /* 1 to enable robust checking	      */
Packit Service 706eca
  #endif
Packit Service 706eca
  #if !defined(DECALLOC)
Packit Service 706eca
  #define DECALLOC  0	      /* 1 to enable memory accounting	      */
Packit Service 706eca
  #endif
Packit Service 706eca
  #if !defined(DECTRACE)
Packit Service 706eca
  #define DECTRACE  0	      /* 1 to trace certain internals, etc.   */
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Tuning parameter for decNumber (arbitrary precision) module      */
Packit Service 706eca
  #if !defined(DECBUFFER)
Packit Service 706eca
  #define DECBUFFER 36	      /* Size basis for local buffers.	This  */
Packit Service 706eca
			      /* should be a common maximum precision */
Packit Service 706eca
			      /* rounded up to a multiple of 4; must  */
Packit Service 706eca
			      /* be zero or positive.		      */
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* ---------------------------------------------------------------- */
Packit Service 706eca
  /* Definitions for all modules (general-purpose)		      */
Packit Service 706eca
  /* ---------------------------------------------------------------- */
Packit Service 706eca
Packit Service 706eca
  /* Local names for common types -- for safety, decNumber modules do */
Packit Service 706eca
  /* not use int or long directly.				      */
Packit Service 706eca
  #define Flag	 uint8_t
Packit Service 706eca
  #define Byte	 int8_t
Packit Service 706eca
  #define uByte  uint8_t
Packit Service 706eca
  #define Short  int16_t
Packit Service 706eca
  #define uShort uint16_t
Packit Service 706eca
  #define Int	 int32_t
Packit Service 706eca
  #define uInt	 uint32_t
Packit Service 706eca
  #define Unit	 decNumberUnit
Packit Service 706eca
  #if DECUSE64
Packit Service 706eca
  #define Long	 int64_t
Packit Service 706eca
  #define uLong  uint64_t
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Development-use definitions				      */
Packit Service 706eca
  typedef long int LI;	      /* for printf arguments only	      */
Packit Service 706eca
  #define DECNOINT  0	      /* 1 to check no internal use of 'int'  */
Packit Service 706eca
			      /*   or stdint types		      */
Packit Service 706eca
  #if DECNOINT
Packit Service 706eca
    /* if these interfere with your C includes, do not set DECNOINT   */
Packit Service 706eca
    #define int     ?	      /* enable to ensure that plain C 'int'  */
Packit Service 706eca
    #define long    ??	      /* .. or 'long' types are not used      */
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Shared lookup tables					      */
Packit Service 706eca
  extern const uByte  DECSTICKYTAB[10]; /* re-round digits if sticky  */
Packit Service 706eca
  extern const uInt   DECPOWERS[10];	/* powers of ten table	      */
Packit Service 706eca
  /* The following are included from decDPD.h			      */
Packit Service 706eca
  #include "decDPDSymbols.h"
Packit Service 706eca
  extern const uShort DPD2BIN[1024];	/* DPD -> 0-999 	      */
Packit Service 706eca
  extern const uShort BIN2DPD[1000];	/* 0-999 -> DPD 	      */
Packit Service 706eca
  extern const uInt   DPD2BINK[1024];	/* DPD -> 0-999000	      */
Packit Service 706eca
  extern const uInt   DPD2BINM[1024];	/* DPD -> 0-999000000	      */
Packit Service 706eca
  extern const uByte  DPD2BCD8[4096];	/* DPD -> ddd + len	      */
Packit Service 706eca
  extern const uByte  BIN2BCD8[4000];	/* 0-999 -> ddd + len	      */
Packit Service 706eca
  extern const uShort BCD2DPD[2458];	/* 0-0x999 -> DPD (0x999=2457)*/
Packit Service 706eca
Packit Service 706eca
  /* LONGMUL32HI -- set w=(u*v)>>32, where w, u, and v are uInts      */
Packit Service 706eca
  /* (that is, sets w to be the high-order word of the 64-bit result; */
Packit Service 706eca
  /* the low-order word is simply u*v.) 			      */
Packit Service 706eca
  /* This version is derived from Knuth via Hacker's Delight;	      */
Packit Service 706eca
  /* it seems to optimize better than some others tried 	      */
Packit Service 706eca
  #define LONGMUL32HI(w, u, v) {	     \
Packit Service 706eca
    uInt u0, u1, v0, v1, w0, w1, w2, t;      \
Packit Service 706eca
    u0=u & 0xffff; u1=u>>16;		     \
Packit Service 706eca
    v0=v & 0xffff; v1=v>>16;		     \
Packit Service 706eca
    w0=u0*v0;				     \
Packit Service 706eca
    t=u1*v0 + (w0>>16); 		     \
Packit Service 706eca
    w1=t & 0xffff; w2=t>>16;		     \
Packit Service 706eca
    w1=u0*v1 + w1;			     \
Packit Service 706eca
    (w)=u1*v1 + w2 + (w1>>16);}
Packit Service 706eca
Packit Service 706eca
  /* ROUNDUP -- round an integer up to a multiple of n		      */
Packit Service 706eca
  #define ROUNDUP(i, n) ((((i)+(n)-1)/n)*n)
Packit Service 706eca
  #define ROUNDUP4(i)	(((i)+3)&~3)	/* special for n=4	      */
Packit Service 706eca
Packit Service 706eca
  /* ROUNDDOWN -- round an integer down to a multiple of n	      */
Packit Service 706eca
  #define ROUNDDOWN(i, n) (((i)/n)*n)
Packit Service 706eca
  #define ROUNDDOWN4(i)   ((i)&~3)	/* special for n=4	      */
Packit Service 706eca
Packit Service 706eca
  /* References to multi-byte sequences under different sizes; these  */
Packit Service 706eca
  /* require locally declared variables, but do not violate strict    */
Packit Service 706eca
  /* aliasing or alignment (as did the UINTAT simple cast to uInt).   */
Packit Service 706eca
  /* Variables needed are uswork, uiwork, etc. [so do not use at same */
Packit Service 706eca
  /* level in an expression, e.g., UBTOUI(x)==UBTOUI(y) may fail].    */
Packit Service 706eca
Packit Service 706eca
  /* Return a uInt, etc., from bytes starting at a char* or uByte*    */
Packit Service 706eca
  #define UBTOUS(b)  (memcpy((void *)&uswork, b, 2), uswork)
Packit Service 706eca
  #define UBTOUI(b)  (memcpy((void *)&uiwork, b, 4), uiwork)
Packit Service 706eca
Packit Service 706eca
  /* Store a uInt, etc., into bytes starting at a char* or uByte*.    */
Packit Service 706eca
  /* Has to use uiwork because i may be an expression.		      */
Packit Service 706eca
  #define UBFROMUS(b, i)  (uswork=(i), memcpy(b, (void *)&uswork, 2))
Packit Service 706eca
  #define UBFROMUI(b, i)  (uiwork=(i), memcpy(b, (void *)&uiwork, 4))
Packit Service 706eca
Packit Service 706eca
  /* X10 and X100 -- multiply integer i by 10 or 100		      */
Packit Service 706eca
  /* [shifts are usually faster than multiply; could be conditional]  */
Packit Service 706eca
  #define X10(i)  (((i)<<1)+((i)<<3))
Packit Service 706eca
  #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
Packit Service 706eca
Packit Service 706eca
  /* MAXI and MINI -- general max & min (not in ANSI) for integers    */
Packit Service 706eca
  #define MAXI(x,y) ((x)<(y)?(y):(x))
Packit Service 706eca
  #define MINI(x,y) ((x)>(y)?(y):(x))
Packit Service 706eca
Packit Service 706eca
  /* Useful constants						      */
Packit Service 706eca
  #define BILLION      1000000000	     /* 10**9		      */
Packit Service 706eca
  /* CHARMASK: 0x30303030 for ASCII/UTF8; 0xF0F0F0F0 for EBCDIC       */
Packit Service 706eca
  #define CHARMASK ((((((((uInt)'0')<<8)+'0')<<8)+'0')<<8)+'0')
Packit Service 706eca
Packit Service 706eca
Packit Service 706eca
  /* ---------------------------------------------------------------- */
Packit Service 706eca
  /* Definitions for arbitary-precision modules (only valid after     */
Packit Service 706eca
  /* decNumber.h has been included)				      */
Packit Service 706eca
  /* ---------------------------------------------------------------- */
Packit Service 706eca
Packit Service 706eca
  /* Limits and constants					      */
Packit Service 706eca
  #define DECNUMMAXP 999999999	/* maximum precision code can handle  */
Packit Service 706eca
  #define DECNUMMAXE 999999999	/* maximum adjusted exponent ditto    */
Packit Service 706eca
  #define DECNUMMINE -999999999 /* minimum adjusted exponent ditto    */
Packit Service 706eca
  #if (DECNUMMAXP != DEC_MAX_DIGITS)
Packit Service 706eca
    #error Maximum digits mismatch
Packit Service 706eca
  #endif
Packit Service 706eca
  #if (DECNUMMAXE != DEC_MAX_EMAX)
Packit Service 706eca
    #error Maximum exponent mismatch
Packit Service 706eca
  #endif
Packit Service 706eca
  #if (DECNUMMINE != DEC_MIN_EMIN)
Packit Service 706eca
    #error Minimum exponent mismatch
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN       */
Packit Service 706eca
  /* digits, and D2UTABLE -- the initializer for the D2U table	      */
Packit Service 706eca
  #if	DECDPUN==1
Packit Service 706eca
    #define DECDPUNMAX 9
Packit Service 706eca
    #define D2UTABLE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,  \
Packit Service 706eca
		      18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, \
Packit Service 706eca
		      33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, \
Packit Service 706eca
		      48,49}
Packit Service 706eca
  #elif DECDPUN==2
Packit Service 706eca
    #define DECDPUNMAX 99
Packit Service 706eca
    #define D2UTABLE {0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,  \
Packit Service 706eca
		      11,11,12,12,13,13,14,14,15,15,16,16,17,17,18, \
Packit Service 706eca
		      18,19,19,20,20,21,21,22,22,23,23,24,24,25}
Packit Service 706eca
  #elif DECDPUN==3
Packit Service 706eca
    #define DECDPUNMAX 999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,  \
Packit Service 706eca
		      8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13, \
Packit Service 706eca
		      13,14,14,14,15,15,15,16,16,16,17}
Packit Service 706eca
  #elif DECDPUN==4
Packit Service 706eca
    #define DECDPUNMAX 9999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,  \
Packit Service 706eca
		      6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11, \
Packit Service 706eca
		      11,11,11,12,12,12,12,13}
Packit Service 706eca
  #elif DECDPUN==5
Packit Service 706eca
    #define DECDPUNMAX 99999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,  \
Packit Service 706eca
		      5,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,  \
Packit Service 706eca
		      9,9,10,10,10,10}
Packit Service 706eca
  #elif DECDPUN==6
Packit Service 706eca
    #define DECDPUNMAX 999999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,  \
Packit Service 706eca
		      4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8,  \
Packit Service 706eca
		      8,8,8,8,8,9}
Packit Service 706eca
  #elif DECDPUN==7
Packit Service 706eca
    #define DECDPUNMAX 9999999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,  \
Packit Service 706eca
		      4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,7,  \
Packit Service 706eca
		      7,7,7,7,7,7}
Packit Service 706eca
  #elif DECDPUN==8
Packit Service 706eca
    #define DECDPUNMAX 99999999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,  \
Packit Service 706eca
		      3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,6,6,6,  \
Packit Service 706eca
		      6,6,6,6,6,7}
Packit Service 706eca
  #elif DECDPUN==9
Packit Service 706eca
    #define DECDPUNMAX 999999999
Packit Service 706eca
    #define D2UTABLE {0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,  \
Packit Service 706eca
		      3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,  \
Packit Service 706eca
		      5,5,6,6,6,6}
Packit Service 706eca
  #elif defined(DECDPUN)
Packit Service 706eca
    #error DECDPUN must be in the range 1-9
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* ----- Shared data (in decNumber.c) ----- */
Packit Service 706eca
  /* Public lookup table used by the D2U macro (see below)	      */
Packit Service 706eca
  #define DECMAXD2U 49
Packit Service 706eca
  extern const uByte d2utable[DECMAXD2U+1];
Packit Service 706eca
Packit Service 706eca
  /* ----- Macros ----- */
Packit Service 706eca
  /* ISZERO -- return true if decNumber dn is a zero		      */
Packit Service 706eca
  /* [performance-critical in some situations]			      */
Packit Service 706eca
  #define ISZERO(dn) decNumberIsZero(dn)     /* now just a local name */
Packit Service 706eca
Packit Service 706eca
  /* D2U -- return the number of Units needed to hold d digits	      */
Packit Service 706eca
  /* (runtime version, with table lookaside for small d)	      */
Packit Service 706eca
  #if DECDPUN==8
Packit Service 706eca
    #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+7)>>3))
Packit Service 706eca
  #elif DECDPUN==4
Packit Service 706eca
    #define D2U(d) ((unsigned)((d)<=DECMAXD2U?d2utable[d]:((d)+3)>>2))
Packit Service 706eca
  #else
Packit Service 706eca
    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
Packit Service 706eca
  #endif
Packit Service 706eca
  /* SD2U -- static D2U macro (for compile-time calculation)	      */
Packit Service 706eca
  #define SD2U(d) (((d)+DECDPUN-1)/DECDPUN)
Packit Service 706eca
Packit Service 706eca
  /* MSUDIGITS -- returns digits in msu, from digits, calculated      */
Packit Service 706eca
  /* using D2U							      */
Packit Service 706eca
  #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
Packit Service 706eca
Packit Service 706eca
  /* D2N -- return the number of decNumber structs that would be      */
Packit Service 706eca
  /* needed to contain that number of digits (and the initial	      */
Packit Service 706eca
  /* decNumber struct) safely.	Note that one Unit is included in the */
Packit Service 706eca
  /* initial structure.  Used for allocating space that is aligned on */
Packit Service 706eca
  /* a decNumber struct boundary. */
Packit Service 706eca
  #define D2N(d) \
Packit Service 706eca
    ((((SD2U(d)-1)*sizeof(Unit))+sizeof(decNumber)*2-1)/sizeof(decNumber))
Packit Service 706eca
Packit Service 706eca
  /* TODIGIT -- macro to remove the leading digit from the unsigned   */
Packit Service 706eca
  /* integer u at column cut (counting from the right, LSD=0) and     */
Packit Service 706eca
  /* place it as an ASCII character into the character pointed to by  */
Packit Service 706eca
  /* c.  Note that cut must be <= 9, and the maximum value for u is   */
Packit Service 706eca
  /* 2,000,000,000 (as is needed for negative exponents of	      */
Packit Service 706eca
  /* subnormals).  The unsigned integer pow is used as a temporary    */
Packit Service 706eca
  /* variable. */
Packit Service 706eca
  #define TODIGIT(u, cut, c, pow) {	  \
Packit Service 706eca
    *(c)='0';				  \
Packit Service 706eca
    pow=DECPOWERS[cut]*2;		  \
Packit Service 706eca
    if ((u)>pow) {			  \
Packit Service 706eca
      pow*=4;				  \
Packit Service 706eca
      if ((u)>=pow) {(u)-=pow; *(c)+=8;}  \
Packit Service 706eca
      pow/=2;				  \
Packit Service 706eca
      if ((u)>=pow) {(u)-=pow; *(c)+=4;}  \
Packit Service 706eca
      pow/=2;				  \
Packit Service 706eca
      } 				  \
Packit Service 706eca
    if ((u)>=pow) {(u)-=pow; *(c)+=2;}	  \
Packit Service 706eca
    pow/=2;				  \
Packit Service 706eca
    if ((u)>=pow) {(u)-=pow; *(c)+=1;}	  \
Packit Service 706eca
    }
Packit Service 706eca
Packit Service 706eca
  /* ---------------------------------------------------------------- */
Packit Service 706eca
  /* Definitions for fixed-precision modules (only valid after	      */
Packit Service 706eca
  /* decSingle.h, decDouble.h, or decQuad.h has been included)	      */
Packit Service 706eca
  /* ---------------------------------------------------------------- */
Packit Service 706eca
Packit Service 706eca
  /* bcdnum -- a structure describing a format-independent finite     */
Packit Service 706eca
  /* number, whose coefficient is a string of bcd8 uBytes	      */
Packit Service 706eca
  typedef struct {
Packit Service 706eca
    uByte   *msd;	      /* -> most significant digit	      */
Packit Service 706eca
    uByte   *lsd;	      /* -> least ditto 		      */
Packit Service 706eca
    uInt     sign;	      /* 0=positive, DECFLOAT_Sign=negative   */
Packit Service 706eca
    Int      exponent;	      /* Unadjusted signed exponent (q), or   */
Packit Service 706eca
			      /* DECFLOAT_NaN etc. for a special      */
Packit Service 706eca
    } bcdnum;
Packit Service 706eca
Packit Service 706eca
  /* Test if exponent or bcdnum exponent must be a special, etc.      */
Packit Service 706eca
  #define EXPISSPECIAL(exp) ((exp)>=DECFLOAT_MinSp)
Packit Service 706eca
  #define EXPISINF(exp) (exp==DECFLOAT_Inf)
Packit Service 706eca
  #define EXPISNAN(exp) (exp==DECFLOAT_qNaN || exp==DECFLOAT_sNaN)
Packit Service 706eca
  #define NUMISSPECIAL(num) (EXPISSPECIAL((num)->exponent))
Packit Service 706eca
Packit Service 706eca
  /* Refer to a 32-bit word or byte in a decFloat (df) by big-endian  */
Packit Service 706eca
  /* (array) notation (the 0 word or byte contains the sign bit),     */
Packit Service 706eca
  /* automatically adjusting for endianness; similarly address a word */
Packit Service 706eca
  /* in the next-wider format (decFloatWider, or dfw)		      */
Packit Service 706eca
  #define DECWORDS  (DECBYTES/4)
Packit Service 706eca
  #define DECWWORDS (DECWBYTES/4)
Packit Service 706eca
  #if DECLITEND
Packit Service 706eca
    #define DFBYTE(df, off)   ((df)->bytes[DECBYTES-1-(off)])
Packit Service 706eca
    #define DFWORD(df, off)   ((df)->words[DECWORDS-1-(off)])
Packit Service 706eca
    #define DFWWORD(dfw, off) ((dfw)->words[DECWWORDS-1-(off)])
Packit Service 706eca
  #else
Packit Service 706eca
    #define DFBYTE(df, off)   ((df)->bytes[off])
Packit Service 706eca
    #define DFWORD(df, off)   ((df)->words[off])
Packit Service 706eca
    #define DFWWORD(dfw, off) ((dfw)->words[off])
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Tests for sign or specials, directly on DECFLOATs		      */
Packit Service 706eca
  #define DFISSIGNED(df)   (DFWORD(df, 0)&0x80000000)
Packit Service 706eca
  #define DFISSPECIAL(df) ((DFWORD(df, 0)&0x78000000)==0x78000000)
Packit Service 706eca
  #define DFISINF(df)	  ((DFWORD(df, 0)&0x7c000000)==0x78000000)
Packit Service 706eca
  #define DFISNAN(df)	  ((DFWORD(df, 0)&0x7c000000)==0x7c000000)
Packit Service 706eca
  #define DFISQNAN(df)	  ((DFWORD(df, 0)&0x7e000000)==0x7c000000)
Packit Service 706eca
  #define DFISSNAN(df)	  ((DFWORD(df, 0)&0x7e000000)==0x7e000000)
Packit Service 706eca
Packit Service 706eca
  /* Shared lookup tables					      */
Packit Service 706eca
#include "decCommonSymbols.h"
Packit Service 706eca
  extern const uInt   DECCOMBMSD[64];	/* Combination field -> MSD   */
Packit Service 706eca
  extern const uInt   DECCOMBFROM[48];	/* exp+msd -> Combination     */
Packit Service 706eca
Packit Service 706eca
  /* Private generic (utility) routine				      */
Packit Service 706eca
  #if DECCHECK || DECTRACE
Packit Service 706eca
    extern void decShowNum(const bcdnum *, const char *);
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
  /* Format-dependent macros and constants			      */
Packit Service 706eca
  #if defined(DECPMAX)
Packit Service 706eca
Packit Service 706eca
    /* Useful constants 					      */
Packit Service 706eca
    #define DECPMAX9  (ROUNDUP(DECPMAX, 9)/9)  /* 'Pmax' in 10**9s    */
Packit Service 706eca
    /* Top words for a zero					      */
Packit Service 706eca
    #define SINGLEZERO	 0x22500000
Packit Service 706eca
    #define DOUBLEZERO	 0x22380000
Packit Service 706eca
    #define QUADZERO	 0x22080000
Packit Service 706eca
    /* [ZEROWORD is defined to be one of these in the DFISZERO macro] */
Packit Service 706eca
Packit Service 706eca
    /* Format-dependent common tests:				      */
Packit Service 706eca
    /*	 DFISZERO   -- test for (any) zero			      */
Packit Service 706eca
    /*	 DFISCCZERO -- test for coefficient continuation being zero   */
Packit Service 706eca
    /*	 DFISCC01   -- test for coefficient contains only 0s and 1s   */
Packit Service 706eca
    /*	 DFISINT    -- test for finite and exponent q=0 	      */
Packit Service 706eca
    /*	 DFISUINT01 -- test for sign=0, finite, exponent q=0, and     */
Packit Service 706eca
    /*		       MSD=0 or 1				      */
Packit Service 706eca
    /*	 ZEROWORD is also defined here. 			      */
Packit Service 706eca
    /* In DFISZERO the first test checks the least-significant word   */
Packit Service 706eca
    /* (most likely to be non-zero); the penultimate tests MSD and    */
Packit Service 706eca
    /* DPDs in the signword, and the final test excludes specials and */
Packit Service 706eca
    /* MSD>7.  DFISINT similarly has to allow for the two forms of    */
Packit Service 706eca
    /* MSD codes.  DFISUINT01 only has to allow for one form of MSD   */
Packit Service 706eca
    /* code.							      */
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
      #define ZEROWORD SINGLEZERO
Packit Service 706eca
      /* [test macros not needed except for Zero]		      */
Packit Service 706eca
      #define DFISZERO(df)  ((DFWORD(df, 0)&0x1c0fffff)==0	   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x60000000)!=0x60000000)
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
      #define ZEROWORD DOUBLEZERO
Packit Service 706eca
      #define DFISZERO(df)  ((DFWORD(df, 1)==0			   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x1c03ffff)==0	   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x60000000)!=0x60000000))
Packit Service 706eca
      #define DFISINT(df) ((DFWORD(df, 0)&0x63fc0000)==0x22380000  \
Packit Service 706eca
			 ||(DFWORD(df, 0)&0x7bfc0000)==0x6a380000)
Packit Service 706eca
      #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbfc0000)==0x22380000)
Packit Service 706eca
      #define DFISCCZERO(df) (DFWORD(df, 1)==0			   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x0003ffff)==0)
Packit Service 706eca
      #define DFISCC01(df)  ((DFWORD(df, 0)&~0xfffc9124)==0	   \
Packit Service 706eca
			  && (DFWORD(df, 1)&~0x49124491)==0)
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
      #define ZEROWORD QUADZERO
Packit Service 706eca
      #define DFISZERO(df)  ((DFWORD(df, 3)==0			   \
Packit Service 706eca
			  &&  DFWORD(df, 2)==0			   \
Packit Service 706eca
			  &&  DFWORD(df, 1)==0			   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x1c003fff)==0	   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x60000000)!=0x60000000))
Packit Service 706eca
      #define DFISINT(df) ((DFWORD(df, 0)&0x63ffc000)==0x22080000  \
Packit Service 706eca
			 ||(DFWORD(df, 0)&0x7bffc000)==0x6a080000)
Packit Service 706eca
      #define DFISUINT01(df) ((DFWORD(df, 0)&0xfbffc000)==0x22080000)
Packit Service 706eca
      #define DFISCCZERO(df) (DFWORD(df, 3)==0			   \
Packit Service 706eca
			  &&  DFWORD(df, 2)==0			   \
Packit Service 706eca
			  &&  DFWORD(df, 1)==0			   \
Packit Service 706eca
			  && (DFWORD(df, 0)&0x00003fff)==0)
Packit Service 706eca
Packit Service 706eca
      #define DFISCC01(df)   ((DFWORD(df, 0)&~0xffffc912)==0	   \
Packit Service 706eca
			  &&  (DFWORD(df, 1)&~0x44912449)==0	   \
Packit Service 706eca
			  &&  (DFWORD(df, 2)&~0x12449124)==0	   \
Packit Service 706eca
			  &&  (DFWORD(df, 3)&~0x49124491)==0)
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
    /* Macros to test if a certain 10 bits of a uInt or pair of uInts */
Packit Service 706eca
    /* are a canonical declet [higher or lower bits are ignored].     */
Packit Service 706eca
    /* declet is at offset 0 (from the right) in a uInt:	      */
Packit Service 706eca
    #define CANONDPD(dpd) (((dpd)&0x300)==0 || ((dpd)&0x6e)!=0x6e)
Packit Service 706eca
    /* declet is at offset k (a multiple of 2) in a uInt:	      */
Packit Service 706eca
    #define CANONDPDOFF(dpd, k) (((dpd)&(0x300<<(k)))==0	    \
Packit Service 706eca
      || ((dpd)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
Packit Service 706eca
    /* declet is at offset k (a multiple of 2) in a pair of uInts:    */
Packit Service 706eca
    /* [the top 2 bits will always be in the more-significant uInt]   */
Packit Service 706eca
    #define CANONDPDTWO(hi, lo, k) (((hi)&(0x300>>(32-(k))))==0     \
Packit Service 706eca
      || ((hi)&(0x6e>>(32-(k))))!=(0x6e>>(32-(k)))		    \
Packit Service 706eca
      || ((lo)&(((uInt)0x6e)<<(k)))!=(((uInt)0x6e)<<(k)))
Packit Service 706eca
Packit Service 706eca
    /* Macro to test whether a full-length (length DECPMAX) BCD8      */
Packit Service 706eca
    /* coefficient, starting at uByte u, is all zeros		      */
Packit Service 706eca
    /* Test just the LSWord first, then the remainder as a sequence   */
Packit Service 706eca
    /* of tests in order to avoid same-level use of UBTOUI	      */
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
      #define ISCOEFFZERO(u) (					    \
Packit Service 706eca
	   UBTOUI((u)+DECPMAX-4)==0				    \
Packit Service 706eca
	&& UBTOUS((u)+DECPMAX-6)==0				    \
Packit Service 706eca
	&& *(u)==0)
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
      #define ISCOEFFZERO(u) (					    \
Packit Service 706eca
	   UBTOUI((u)+DECPMAX-4)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-8)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-12)==0				    \
Packit Service 706eca
	&& UBTOUI(u)==0)
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
      #define ISCOEFFZERO(u) (					    \
Packit Service 706eca
	   UBTOUI((u)+DECPMAX-4)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-8)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-12)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-16)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-20)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-24)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-28)==0				    \
Packit Service 706eca
	&& UBTOUI((u)+DECPMAX-32)==0				    \
Packit Service 706eca
	&& UBTOUS(u)==0)
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
    /* Macros and masks for the exponent continuation field and MSD   */
Packit Service 706eca
    /* Get the exponent continuation from a decFloat *df as an Int    */
Packit Service 706eca
    #define GETECON(df) ((Int)((DFWORD((df), 0)&0x03ffffff)>>(32-6-DECECONL)))
Packit Service 706eca
    /* Ditto, from the next-wider format			      */
Packit Service 706eca
    #define GETWECON(df) ((Int)((DFWWORD((df), 0)&0x03ffffff)>>(32-6-DECWECONL)))
Packit Service 706eca
    /* Get the biased exponent similarly			      */
Packit Service 706eca
    #define GETEXP(df)	((Int)(DECCOMBEXP[DFWORD((df), 0)>>26]+GETECON(df)))
Packit Service 706eca
    /* Get the unbiased exponent similarly			      */
Packit Service 706eca
    #define GETEXPUN(df) ((Int)GETEXP(df)-DECBIAS)
Packit Service 706eca
    /* Get the MSD similarly (as uInt)				      */
Packit Service 706eca
    #define GETMSD(df)	 (DECCOMBMSD[DFWORD((df), 0)>>26])
Packit Service 706eca
Packit Service 706eca
    /* Compile-time computes of the exponent continuation field masks */
Packit Service 706eca
    /* full exponent continuation field:			      */
Packit Service 706eca
    #define ECONMASK ((0x03ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
Packit Service 706eca
    /* same, not including its first digit (the qNaN/sNaN selector):  */
Packit Service 706eca
    #define ECONNANMASK ((0x01ffffff>>(32-6-DECECONL))<<(32-6-DECECONL))
Packit Service 706eca
Packit Service 706eca
    /* Macros to decode the coefficient in a finite decFloat *df into */
Packit Service 706eca
    /* a BCD string (uByte *bcdin) of length DECPMAX uBytes.	      */
Packit Service 706eca
Packit Service 706eca
    /* In-line sequence to convert least significant 10 bits of uInt  */
Packit Service 706eca
    /* dpd to three BCD8 digits starting at uByte u.  Note that an    */
Packit Service 706eca
    /* extra byte is written to the right of the three digits because */
Packit Service 706eca
    /* four bytes are moved at a time for speed; the alternative      */
Packit Service 706eca
    /* macro moves exactly three bytes (usually slower).	      */
Packit Service 706eca
    #define dpd2bcd8(u, dpd)  memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 4)
Packit Service 706eca
    #define dpd2bcd83(u, dpd) memcpy(u, &DPD2BCD8[((dpd)&0x3ff)*4], 3)
Packit Service 706eca
Packit Service 706eca
    /* Decode the declets.  After extracting each one, it is decoded  */
Packit Service 706eca
    /* to BCD8 using a table lookup (also used for variable-length    */
Packit Service 706eca
    /* decode).  Each DPD decode is 3 bytes BCD8 plus a one-byte      */
Packit Service 706eca
    /* length which is not used, here).  Fixed-length 4-byte moves    */
Packit Service 706eca
    /* are fast, however, almost everywhere, and so are used except   */
Packit Service 706eca
    /* for the final three bytes (to avoid overrun).  The code below  */
Packit Service 706eca
    /* is 36 instructions for Doubles and about 70 for Quads, even    */
Packit Service 706eca
    /* on IA32. 						      */
Packit Service 706eca
Packit Service 706eca
    /* Two macros are defined for each format:			      */
Packit Service 706eca
    /*	 GETCOEFF extracts the coefficient of the current format      */
Packit Service 706eca
    /*	 GETWCOEFF extracts the coefficient of the next-wider format. */
Packit Service 706eca
    /* The latter is a copy of the next-wider GETCOEFF using DFWWORD. */
Packit Service 706eca
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
    #define GETCOEFF(df, bcd) { 			 \
Packit Service 706eca
      uInt sourhi=DFWORD(df, 0);			 \
Packit Service 706eca
      *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
Packit Service 706eca
      dpd2bcd8(bcd+1, sourhi>>10);			 \
Packit Service 706eca
      dpd2bcd83(bcd+4, sourhi);}
Packit Service 706eca
    #define GETWCOEFF(df, bcd) {			 \
Packit Service 706eca
      uInt sourhi=DFWWORD(df, 0);			 \
Packit Service 706eca
      uInt sourlo=DFWWORD(df, 1);			 \
Packit Service 706eca
      *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
Packit Service 706eca
      dpd2bcd8(bcd+1, sourhi>>8);			 \
Packit Service 706eca
      dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30));	 \
Packit Service 706eca
      dpd2bcd8(bcd+7, sourlo>>20);			 \
Packit Service 706eca
      dpd2bcd8(bcd+10, sourlo>>10);			 \
Packit Service 706eca
      dpd2bcd83(bcd+13, sourlo);}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
    #define GETCOEFF(df, bcd) { 			 \
Packit Service 706eca
      uInt sourhi=DFWORD(df, 0);			 \
Packit Service 706eca
      uInt sourlo=DFWORD(df, 1);			 \
Packit Service 706eca
      *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
Packit Service 706eca
      dpd2bcd8(bcd+1, sourhi>>8);			 \
Packit Service 706eca
      dpd2bcd8(bcd+4, (sourhi<<2) | (sourlo>>30));	 \
Packit Service 706eca
      dpd2bcd8(bcd+7, sourlo>>20);			 \
Packit Service 706eca
      dpd2bcd8(bcd+10, sourlo>>10);			 \
Packit Service 706eca
      dpd2bcd83(bcd+13, sourlo);}
Packit Service 706eca
    #define GETWCOEFF(df, bcd) {			 \
Packit Service 706eca
      uInt sourhi=DFWWORD(df, 0);			 \
Packit Service 706eca
      uInt sourmh=DFWWORD(df, 1);			 \
Packit Service 706eca
      uInt sourml=DFWWORD(df, 2);			 \
Packit Service 706eca
      uInt sourlo=DFWWORD(df, 3);			 \
Packit Service 706eca
      *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
Packit Service 706eca
      dpd2bcd8(bcd+1, sourhi>>4);			 \
Packit Service 706eca
      dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26));	 \
Packit Service 706eca
      dpd2bcd8(bcd+7, sourmh>>16);			 \
Packit Service 706eca
      dpd2bcd8(bcd+10, sourmh>>6);			 \
Packit Service 706eca
      dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28));	 \
Packit Service 706eca
      dpd2bcd8(bcd+16, sourml>>18);			 \
Packit Service 706eca
      dpd2bcd8(bcd+19, sourml>>8);			 \
Packit Service 706eca
      dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30));	 \
Packit Service 706eca
      dpd2bcd8(bcd+25, sourlo>>20);			 \
Packit Service 706eca
      dpd2bcd8(bcd+28, sourlo>>10);			 \
Packit Service 706eca
      dpd2bcd83(bcd+31, sourlo);}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
    #define GETCOEFF(df, bcd) { 			 \
Packit Service 706eca
      uInt sourhi=DFWORD(df, 0);			 \
Packit Service 706eca
      uInt sourmh=DFWORD(df, 1);			 \
Packit Service 706eca
      uInt sourml=DFWORD(df, 2);			 \
Packit Service 706eca
      uInt sourlo=DFWORD(df, 3);			 \
Packit Service 706eca
      *(bcd)=(uByte)DECCOMBMSD[sourhi>>26];		 \
Packit Service 706eca
      dpd2bcd8(bcd+1, sourhi>>4);			 \
Packit Service 706eca
      dpd2bcd8(bcd+4, ((sourhi)<<6) | (sourmh>>26));	 \
Packit Service 706eca
      dpd2bcd8(bcd+7, sourmh>>16);			 \
Packit Service 706eca
      dpd2bcd8(bcd+10, sourmh>>6);			 \
Packit Service 706eca
      dpd2bcd8(bcd+13, ((sourmh)<<4) | (sourml>>28));	 \
Packit Service 706eca
      dpd2bcd8(bcd+16, sourml>>18);			 \
Packit Service 706eca
      dpd2bcd8(bcd+19, sourml>>8);			 \
Packit Service 706eca
      dpd2bcd8(bcd+22, ((sourml)<<2) | (sourlo>>30));	 \
Packit Service 706eca
      dpd2bcd8(bcd+25, sourlo>>20);			 \
Packit Service 706eca
      dpd2bcd8(bcd+28, sourlo>>10);			 \
Packit Service 706eca
      dpd2bcd83(bcd+31, sourlo);}
Packit Service 706eca
Packit Service 706eca
      #define GETWCOEFF(df, bcd) {??} /* [should never be used]       */
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
    /* Macros to decode the coefficient in a finite decFloat *df into */
Packit Service 706eca
    /* a base-billion uInt array, with the least-significant	      */
Packit Service 706eca
    /* 0-999999999 'digit' at offset 0. 			      */
Packit Service 706eca
Packit Service 706eca
    /* Decode the declets.  After extracting each one, it is decoded  */
Packit Service 706eca
    /* to binary using a table lookup.	Three tables are used; one    */
Packit Service 706eca
    /* the usual DPD to binary, the other two pre-multiplied by 1000  */
Packit Service 706eca
    /* and 1000000 to avoid multiplication during decode.  These      */
Packit Service 706eca
    /* tables can also be used for multiplying up the MSD as the DPD  */
Packit Service 706eca
    /* code for 0 through 9 is the identity.			      */
Packit Service 706eca
    #define DPD2BIN0 DPD2BIN	     /* for prettier code	      */
Packit Service 706eca
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
    #define GETCOEFFBILL(df, buf) {			      \
Packit Service 706eca
      uInt sourhi=DFWORD(df, 0);			      \
Packit Service 706eca
      (buf)[0]=DPD2BIN0[sourhi&0x3ff]			      \
Packit Service 706eca
	      +DPD2BINK[(sourhi>>10)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
    #define GETCOEFFBILL(df, buf) {			      \
Packit Service 706eca
      uInt sourhi, sourlo;				      \
Packit Service 706eca
      sourlo=DFWORD(df, 1);				      \
Packit Service 706eca
      (buf)[0]=DPD2BIN0[sourlo&0x3ff]			      \
Packit Service 706eca
	      +DPD2BINK[(sourlo>>10)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[(sourlo>>20)&0x3ff];		      \
Packit Service 706eca
      sourhi=DFWORD(df, 0);				      \
Packit Service 706eca
      (buf)[1]=DPD2BIN0[((sourhi<<2) | (sourlo>>30))&0x3ff]   \
Packit Service 706eca
	      +DPD2BINK[(sourhi>>8)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
    #define GETCOEFFBILL(df, buf) {			      \
Packit Service 706eca
      uInt sourhi, sourmh, sourml, sourlo;		      \
Packit Service 706eca
      sourlo=DFWORD(df, 3);				      \
Packit Service 706eca
      (buf)[0]=DPD2BIN0[sourlo&0x3ff]			      \
Packit Service 706eca
	      +DPD2BINK[(sourlo>>10)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[(sourlo>>20)&0x3ff];		      \
Packit Service 706eca
      sourml=DFWORD(df, 2);				      \
Packit Service 706eca
      (buf)[1]=DPD2BIN0[((sourml<<2) | (sourlo>>30))&0x3ff]   \
Packit Service 706eca
	      +DPD2BINK[(sourml>>8)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[(sourml>>18)&0x3ff];		      \
Packit Service 706eca
      sourmh=DFWORD(df, 1);				      \
Packit Service 706eca
      (buf)[2]=DPD2BIN0[((sourmh<<4) | (sourml>>28))&0x3ff]   \
Packit Service 706eca
	      +DPD2BINK[(sourmh>>6)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[(sourmh>>16)&0x3ff];		      \
Packit Service 706eca
      sourhi=DFWORD(df, 0);				      \
Packit Service 706eca
      (buf)[3]=DPD2BIN0[((sourhi<<6) | (sourmh>>26))&0x3ff]   \
Packit Service 706eca
	      +DPD2BINK[(sourhi>>4)&0x3ff]		      \
Packit Service 706eca
	      +DPD2BINM[DECCOMBMSD[sourhi>>26]];}
Packit Service 706eca
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
    /* Macros to decode the coefficient in a finite decFloat *df into */
Packit Service 706eca
    /* a base-thousand uInt array (of size DECLETS+1, to allow for    */
Packit Service 706eca
    /* the MSD), with the least-significant 0-999 'digit' at offset 0.*/
Packit Service 706eca
Packit Service 706eca
    /* Decode the declets.  After extracting each one, it is decoded  */
Packit Service 706eca
    /* to binary using a table lookup.				      */
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
    #define GETCOEFFTHOU(df, buf) {			      \
Packit Service 706eca
      uInt sourhi=DFWORD(df, 0);			      \
Packit Service 706eca
      (buf)[0]=DPD2BIN[sourhi&0x3ff];			      \
Packit Service 706eca
      (buf)[1]=DPD2BIN[(sourhi>>10)&0x3ff];		      \
Packit Service 706eca
      (buf)[2]=DECCOMBMSD[sourhi>>26];}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
    #define GETCOEFFTHOU(df, buf) {			      \
Packit Service 706eca
      uInt sourhi, sourlo;				      \
Packit Service 706eca
      sourlo=DFWORD(df, 1);				      \
Packit Service 706eca
      (buf)[0]=DPD2BIN[sourlo&0x3ff];			      \
Packit Service 706eca
      (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff];		      \
Packit Service 706eca
      (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff];		      \
Packit Service 706eca
      sourhi=DFWORD(df, 0);				      \
Packit Service 706eca
      (buf)[3]=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff];   \
Packit Service 706eca
      (buf)[4]=DPD2BIN[(sourhi>>8)&0x3ff];		      \
Packit Service 706eca
      (buf)[5]=DECCOMBMSD[sourhi>>26];}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
    #define GETCOEFFTHOU(df, buf) {			      \
Packit Service 706eca
      uInt sourhi, sourmh, sourml, sourlo;		      \
Packit Service 706eca
      sourlo=DFWORD(df, 3);				      \
Packit Service 706eca
      (buf)[0]=DPD2BIN[sourlo&0x3ff];			      \
Packit Service 706eca
      (buf)[1]=DPD2BIN[(sourlo>>10)&0x3ff];		      \
Packit Service 706eca
      (buf)[2]=DPD2BIN[(sourlo>>20)&0x3ff];		      \
Packit Service 706eca
      sourml=DFWORD(df, 2);				      \
Packit Service 706eca
      (buf)[3]=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff];   \
Packit Service 706eca
      (buf)[4]=DPD2BIN[(sourml>>8)&0x3ff];		      \
Packit Service 706eca
      (buf)[5]=DPD2BIN[(sourml>>18)&0x3ff];		      \
Packit Service 706eca
      sourmh=DFWORD(df, 1);				      \
Packit Service 706eca
      (buf)[6]=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff];   \
Packit Service 706eca
      (buf)[7]=DPD2BIN[(sourmh>>6)&0x3ff];		      \
Packit Service 706eca
      (buf)[8]=DPD2BIN[(sourmh>>16)&0x3ff];		      \
Packit Service 706eca
      sourhi=DFWORD(df, 0);				      \
Packit Service 706eca
      (buf)[9]=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff];   \
Packit Service 706eca
      (buf)[10]=DPD2BIN[(sourhi>>4)&0x3ff];		      \
Packit Service 706eca
      (buf)[11]=DECCOMBMSD[sourhi>>26];}
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
Packit Service 706eca
    /* Macros to decode the coefficient in a finite decFloat *df and  */
Packit Service 706eca
    /* add to a base-thousand uInt array (as for GETCOEFFTHOU).       */
Packit Service 706eca
    /* After the addition then most significant 'digit' in the array  */
Packit Service 706eca
    /* might have a value larger then 10 (with a maximum of 19).      */
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
    #define ADDCOEFFTHOU(df, buf) {			      \
Packit Service 706eca
      uInt sourhi=DFWORD(df, 0);			      \
Packit Service 706eca
      (buf)[0]+=DPD2BIN[sourhi&0x3ff];			      \
Packit Service 706eca
      if (buf[0]>999) {buf[0]-=1000; buf[1]++;} 	      \
Packit Service 706eca
      (buf)[1]+=DPD2BIN[(sourhi>>10)&0x3ff];		      \
Packit Service 706eca
      if (buf[1]>999) {buf[1]-=1000; buf[2]++;} 	      \
Packit Service 706eca
      (buf)[2]+=DECCOMBMSD[sourhi>>26];}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
    #define ADDCOEFFTHOU(df, buf) {			      \
Packit Service 706eca
      uInt sourhi, sourlo;				      \
Packit Service 706eca
      sourlo=DFWORD(df, 1);				      \
Packit Service 706eca
      (buf)[0]+=DPD2BIN[sourlo&0x3ff];			      \
Packit Service 706eca
      if (buf[0]>999) {buf[0]-=1000; buf[1]++;} 	      \
Packit Service 706eca
      (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff];		      \
Packit Service 706eca
      if (buf[1]>999) {buf[1]-=1000; buf[2]++;} 	      \
Packit Service 706eca
      (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff];		      \
Packit Service 706eca
      if (buf[2]>999) {buf[2]-=1000; buf[3]++;} 	      \
Packit Service 706eca
      sourhi=DFWORD(df, 0);				      \
Packit Service 706eca
      (buf)[3]+=DPD2BIN[((sourhi<<2) | (sourlo>>30))&0x3ff];  \
Packit Service 706eca
      if (buf[3]>999) {buf[3]-=1000; buf[4]++;} 	      \
Packit Service 706eca
      (buf)[4]+=DPD2BIN[(sourhi>>8)&0x3ff];		      \
Packit Service 706eca
      if (buf[4]>999) {buf[4]-=1000; buf[5]++;} 	      \
Packit Service 706eca
      (buf)[5]+=DECCOMBMSD[sourhi>>26];}
Packit Service 706eca
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
    #define ADDCOEFFTHOU(df, buf) {			      \
Packit Service 706eca
      uInt sourhi, sourmh, sourml, sourlo;		      \
Packit Service 706eca
      sourlo=DFWORD(df, 3);				      \
Packit Service 706eca
      (buf)[0]+=DPD2BIN[sourlo&0x3ff];			      \
Packit Service 706eca
      if (buf[0]>999) {buf[0]-=1000; buf[1]++;} 	      \
Packit Service 706eca
      (buf)[1]+=DPD2BIN[(sourlo>>10)&0x3ff];		      \
Packit Service 706eca
      if (buf[1]>999) {buf[1]-=1000; buf[2]++;} 	      \
Packit Service 706eca
      (buf)[2]+=DPD2BIN[(sourlo>>20)&0x3ff];		      \
Packit Service 706eca
      if (buf[2]>999) {buf[2]-=1000; buf[3]++;} 	      \
Packit Service 706eca
      sourml=DFWORD(df, 2);				      \
Packit Service 706eca
      (buf)[3]+=DPD2BIN[((sourml<<2) | (sourlo>>30))&0x3ff];  \
Packit Service 706eca
      if (buf[3]>999) {buf[3]-=1000; buf[4]++;} 	      \
Packit Service 706eca
      (buf)[4]+=DPD2BIN[(sourml>>8)&0x3ff];		      \
Packit Service 706eca
      if (buf[4]>999) {buf[4]-=1000; buf[5]++;} 	      \
Packit Service 706eca
      (buf)[5]+=DPD2BIN[(sourml>>18)&0x3ff];		      \
Packit Service 706eca
      if (buf[5]>999) {buf[5]-=1000; buf[6]++;} 	      \
Packit Service 706eca
      sourmh=DFWORD(df, 1);				      \
Packit Service 706eca
      (buf)[6]+=DPD2BIN[((sourmh<<4) | (sourml>>28))&0x3ff];  \
Packit Service 706eca
      if (buf[6]>999) {buf[6]-=1000; buf[7]++;} 	      \
Packit Service 706eca
      (buf)[7]+=DPD2BIN[(sourmh>>6)&0x3ff];		      \
Packit Service 706eca
      if (buf[7]>999) {buf[7]-=1000; buf[8]++;} 	      \
Packit Service 706eca
      (buf)[8]+=DPD2BIN[(sourmh>>16)&0x3ff];		      \
Packit Service 706eca
      if (buf[8]>999) {buf[8]-=1000; buf[9]++;} 	      \
Packit Service 706eca
      sourhi=DFWORD(df, 0);				      \
Packit Service 706eca
      (buf)[9]+=DPD2BIN[((sourhi<<6) | (sourmh>>26))&0x3ff];  \
Packit Service 706eca
      if (buf[9]>999) {buf[9]-=1000; buf[10]++;}	      \
Packit Service 706eca
      (buf)[10]+=DPD2BIN[(sourhi>>4)&0x3ff];		      \
Packit Service 706eca
      if (buf[10]>999) {buf[10]-=1000; buf[11]++;}	      \
Packit Service 706eca
      (buf)[11]+=DECCOMBMSD[sourhi>>26];}
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
Packit Service 706eca
    /* Set a decFloat to the maximum positive finite number (Nmax)    */
Packit Service 706eca
    #if DECPMAX==7
Packit Service 706eca
    #define DFSETNMAX(df)	     \
Packit Service 706eca
      {DFWORD(df, 0)=0x77f3fcff;}
Packit Service 706eca
    #elif DECPMAX==16
Packit Service 706eca
    #define DFSETNMAX(df)	     \
Packit Service 706eca
      {DFWORD(df, 0)=0x77fcff3f;     \
Packit Service 706eca
       DFWORD(df, 1)=0xcff3fcff;}
Packit Service 706eca
    #elif DECPMAX==34
Packit Service 706eca
    #define DFSETNMAX(df)	     \
Packit Service 706eca
      {DFWORD(df, 0)=0x77ffcff3;     \
Packit Service 706eca
       DFWORD(df, 1)=0xfcff3fcf;     \
Packit Service 706eca
       DFWORD(df, 2)=0xf3fcff3f;     \
Packit Service 706eca
       DFWORD(df, 3)=0xcff3fcff;}
Packit Service 706eca
    #endif
Packit Service 706eca
Packit Service 706eca
  /* [end of format-dependent macros and constants]		      */
Packit Service 706eca
  #endif
Packit Service 706eca
Packit Service 706eca
#else
Packit Service 706eca
  #error decNumberLocal included more than once
Packit Service 706eca
#endif