1169695Skan/* decNumber package local type, tuning, and macro definitions.
2169695Skan   Copyright (C) 2005 Free Software Foundation, Inc.
3169695Skan   Contributed by IBM Corporation.  Author Mike Cowlishaw.
4169695Skan
5169695Skan   This file is part of GCC.
6169695Skan
7169695Skan   GCC is free software; you can redistribute it and/or modify it under
8169695Skan   the terms of the GNU General Public License as published by the Free
9169695Skan   Software Foundation; either version 2, or (at your option) any later
10169695Skan   version.
11169695Skan
12169695Skan   In addition to the permissions in the GNU General Public License,
13169695Skan   the Free Software Foundation gives you unlimited permission to link
14169695Skan   the compiled version of this file into combinations with other
15169695Skan   programs, and to distribute those combinations without any
16169695Skan   restriction coming from the use of this file.  (The General Public
17169695Skan   License restrictions do apply in other respects; for example, they
18169695Skan   cover modification of the file, and distribution when not linked
19169695Skan   into a combine executable.)
20169695Skan
21169695Skan   GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22169695Skan   WARRANTY; without even the implied warranty of MERCHANTABILITY or
23169695Skan   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24169695Skan   for more details.
25169695Skan
26169695Skan   You should have received a copy of the GNU General Public License
27169695Skan   along with GCC; see the file COPYING.  If not, write to the Free
28169695Skan   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29169695Skan   02110-1301, USA.  */
30169695Skan
31169695Skan/* ------------------------------------------------------------------ */
32169695Skan/* This header file is included by all modules in the decNumber       */
33169695Skan/* library, and contains local type definitions, tuning parameters,   */
34169695Skan/* etc.  It must only be included once, and should not need to be     */
35169695Skan/* used by application programs.  decNumber.h must be included first. */
36169695Skan/* ------------------------------------------------------------------ */
37169695Skan
38169695Skan#if !defined(DECNUMBERLOC)
39169695Skan#define DECNUMBERLOC
40169695Skan#define DECNLAUTHOR   "Mike Cowlishaw"	/* Who to blame */
41169695Skan
42169695Skan  /* Local names for common types -- decNumber modules do not use int or
43169695Skan     long directly */
44169695Skan#define Flag   uint8_t
45169695Skan#define Byte   int8_t
46169695Skan#define uByte  uint8_t
47169695Skan#define Short  int16_t
48169695Skan#define uShort uint16_t
49169695Skan#define Int    int32_t
50169695Skan#define uInt   uint32_t
51169695Skan#define Unit   decNumberUnit
52169695Skan
53169695Skan
54169695Skan  /* Tuning parameter */
55169695Skan#define DECBUFFER 36		/* Maximum size basis for local buffers. */
56169695Skan			      /* Should be a common maximum precision */
57169695Skan			      /* rounded up to a multiple of 4; must */
58169695Skan			      /* be non-negative. */
59169695Skan
60169695Skan  /* Conditional code flags -- set these to 0 for best performance */
61169695Skan#define DECCHECK  0		/* 1 to enable robust checking */
62169695Skan#define DECALLOC  0		/* 1 to enable memory allocation accounting */
63169695Skan#define DECTRACE  0		/* 1 to trace critical intermediates, etc. */
64169695Skan
65169695Skan
66169695Skan  /* Development use defines */
67169695Skan#if DECALLOC
68169695Skan     /* if these interfere with your C includes, just comment them out */
69169695Skan#define  int ?			/* enable to ensure we do not use plain C */
70169695Skan#define  long ??		/* .. 'int' or 'long' types from here on */
71169695Skan#endif
72169695Skan
73169695Skan  /* Limits and constants */
74169695Skan#define DECNUMMAXP 999999999	/* maximum precision we can handle (9 digits) */
75169695Skan#define DECNUMMAXE 999999999	/* maximum adjusted exponent ditto (9 digits) */
76169695Skan#define DECNUMMINE -999999999	/* minimum adjusted exponent ditto (9 digits) */
77169695Skan#if (DECNUMMAXP != DEC_MAX_DIGITS)
78169695Skan#error Maximum digits mismatch
79169695Skan#endif
80169695Skan#if (DECNUMMAXE != DEC_MAX_EMAX)
81169695Skan#error Maximum exponent mismatch
82169695Skan#endif
83169695Skan#if (DECNUMMINE != DEC_MIN_EMIN)
84169695Skan#error Minimum exponent mismatch
85169695Skan#endif
86169695Skan
87169695Skan  /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN digits */
88169695Skan#if   DECDPUN==1
89169695Skan#define DECDPUNMAX 9
90169695Skan#elif DECDPUN==2
91169695Skan#define DECDPUNMAX 99
92169695Skan#elif DECDPUN==3
93169695Skan#define DECDPUNMAX 999
94169695Skan#elif DECDPUN==4
95169695Skan#define DECDPUNMAX 9999
96169695Skan#elif DECDPUN==5
97169695Skan#define DECDPUNMAX 99999
98169695Skan#elif DECDPUN==6
99169695Skan#define DECDPUNMAX 999999
100169695Skan#elif DECDPUN==7
101169695Skan#define DECDPUNMAX 9999999
102169695Skan#elif DECDPUN==8
103169695Skan#define DECDPUNMAX 99999999
104169695Skan#elif DECDPUN==9
105169695Skan#define DECDPUNMAX 999999999
106169695Skan#elif defined(DECDPUN)
107169695Skan#error DECDPUN must be in the range 1-9
108169695Skan#endif
109169695Skan
110169695Skan
111169695Skan  /* ----- Shared data ----- */
112169695Skan  /* The powers of of ten array (powers[n]==10**n, 0<=n<=10) */
113169695Skanextern const uInt powers[];
114169695Skan
115169695Skan  /* ----- Macros ----- */
116169695Skan  /* ISZERO -- return true if decNumber dn is a zero */
117169695Skan  /* [performance-critical in some situations] */
118169695Skan#define ISZERO(dn) decNumberIsZero(dn)	/* now just a local name */
119169695Skan
120169695Skan  /* X10 and X100 -- multiply integer i by 10 or 100 */
121169695Skan  /* [shifts are usually faster than multiply; could be conditional] */
122169695Skan#define X10(i)  (((i)<<1)+((i)<<3))
123169695Skan#define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
124169695Skan
125169695Skan  /* D2U -- return the number of Units needed to hold d digits */
126169695Skan#if DECDPUN==8
127169695Skan#define D2U(d) ((unsigned)((d)+7)>>3)
128169695Skan#elif DECDPUN==4
129169695Skan#define D2U(d) ((unsigned)((d)+3)>>2)
130169695Skan#else
131169695Skan#define D2U(d) (((d)+DECDPUN-1)/DECDPUN)
132169695Skan#endif
133169695Skan
134169695Skan#else
135169695Skan#error decNumberLocal included more than once
136169695Skan#endif
137