xref: /openbsd-src/gnu/gcc/libdecnumber/decNumberLocal.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert /* decNumber package local type, tuning, and macro definitions.
2*404b540aSrobert    Copyright (C) 2005 Free Software Foundation, Inc.
3*404b540aSrobert    Contributed by IBM Corporation.  Author Mike Cowlishaw.
4*404b540aSrobert 
5*404b540aSrobert    This file is part of GCC.
6*404b540aSrobert 
7*404b540aSrobert    GCC is free software; you can redistribute it and/or modify it under
8*404b540aSrobert    the terms of the GNU General Public License as published by the Free
9*404b540aSrobert    Software Foundation; either version 2, or (at your option) any later
10*404b540aSrobert    version.
11*404b540aSrobert 
12*404b540aSrobert    In addition to the permissions in the GNU General Public License,
13*404b540aSrobert    the Free Software Foundation gives you unlimited permission to link
14*404b540aSrobert    the compiled version of this file into combinations with other
15*404b540aSrobert    programs, and to distribute those combinations without any
16*404b540aSrobert    restriction coming from the use of this file.  (The General Public
17*404b540aSrobert    License restrictions do apply in other respects; for example, they
18*404b540aSrobert    cover modification of the file, and distribution when not linked
19*404b540aSrobert    into a combine executable.)
20*404b540aSrobert 
21*404b540aSrobert    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22*404b540aSrobert    WARRANTY; without even the implied warranty of MERCHANTABILITY or
23*404b540aSrobert    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24*404b540aSrobert    for more details.
25*404b540aSrobert 
26*404b540aSrobert    You should have received a copy of the GNU General Public License
27*404b540aSrobert    along with GCC; see the file COPYING.  If not, write to the Free
28*404b540aSrobert    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29*404b540aSrobert    02110-1301, USA.  */
30*404b540aSrobert 
31*404b540aSrobert /* ------------------------------------------------------------------ */
32*404b540aSrobert /* This header file is included by all modules in the decNumber       */
33*404b540aSrobert /* library, and contains local type definitions, tuning parameters,   */
34*404b540aSrobert /* etc.  It must only be included once, and should not need to be     */
35*404b540aSrobert /* used by application programs.  decNumber.h must be included first. */
36*404b540aSrobert /* ------------------------------------------------------------------ */
37*404b540aSrobert 
38*404b540aSrobert #if !defined(DECNUMBERLOC)
39*404b540aSrobert #define DECNUMBERLOC
40*404b540aSrobert #define DECNLAUTHOR   "Mike Cowlishaw"	/* Who to blame */
41*404b540aSrobert 
42*404b540aSrobert   /* Local names for common types -- decNumber modules do not use int or
43*404b540aSrobert      long directly */
44*404b540aSrobert #define Flag   uint8_t
45*404b540aSrobert #define Byte   int8_t
46*404b540aSrobert #define uByte  uint8_t
47*404b540aSrobert #define Short  int16_t
48*404b540aSrobert #define uShort uint16_t
49*404b540aSrobert #define Int    int32_t
50*404b540aSrobert #define uInt   uint32_t
51*404b540aSrobert #define Unit   decNumberUnit
52*404b540aSrobert 
53*404b540aSrobert 
54*404b540aSrobert   /* Tuning parameter */
55*404b540aSrobert #define DECBUFFER 36		/* Maximum size basis for local buffers. */
56*404b540aSrobert 			      /* Should be a common maximum precision */
57*404b540aSrobert 			      /* rounded up to a multiple of 4; must */
58*404b540aSrobert 			      /* be non-negative. */
59*404b540aSrobert 
60*404b540aSrobert   /* Conditional code flags -- set these to 0 for best performance */
61*404b540aSrobert #define DECCHECK  0		/* 1 to enable robust checking */
62*404b540aSrobert #define DECALLOC  0		/* 1 to enable memory allocation accounting */
63*404b540aSrobert #define DECTRACE  0		/* 1 to trace critical intermediates, etc. */
64*404b540aSrobert 
65*404b540aSrobert 
66*404b540aSrobert   /* Development use defines */
67*404b540aSrobert #if DECALLOC
68*404b540aSrobert      /* if these interfere with your C includes, just comment them out */
69*404b540aSrobert #define  int ?			/* enable to ensure we do not use plain C */
70*404b540aSrobert #define  long ??		/* .. 'int' or 'long' types from here on */
71*404b540aSrobert #endif
72*404b540aSrobert 
73*404b540aSrobert   /* Limits and constants */
74*404b540aSrobert #define DECNUMMAXP 999999999	/* maximum precision we can handle (9 digits) */
75*404b540aSrobert #define DECNUMMAXE 999999999	/* maximum adjusted exponent ditto (9 digits) */
76*404b540aSrobert #define DECNUMMINE -999999999	/* minimum adjusted exponent ditto (9 digits) */
77*404b540aSrobert #if (DECNUMMAXP != DEC_MAX_DIGITS)
78*404b540aSrobert #error Maximum digits mismatch
79*404b540aSrobert #endif
80*404b540aSrobert #if (DECNUMMAXE != DEC_MAX_EMAX)
81*404b540aSrobert #error Maximum exponent mismatch
82*404b540aSrobert #endif
83*404b540aSrobert #if (DECNUMMINE != DEC_MIN_EMIN)
84*404b540aSrobert #error Minimum exponent mismatch
85*404b540aSrobert #endif
86*404b540aSrobert 
87*404b540aSrobert   /* Set DECDPUNMAX -- the maximum integer that fits in DECDPUN digits */
88*404b540aSrobert #if   DECDPUN==1
89*404b540aSrobert #define DECDPUNMAX 9
90*404b540aSrobert #elif DECDPUN==2
91*404b540aSrobert #define DECDPUNMAX 99
92*404b540aSrobert #elif DECDPUN==3
93*404b540aSrobert #define DECDPUNMAX 999
94*404b540aSrobert #elif DECDPUN==4
95*404b540aSrobert #define DECDPUNMAX 9999
96*404b540aSrobert #elif DECDPUN==5
97*404b540aSrobert #define DECDPUNMAX 99999
98*404b540aSrobert #elif DECDPUN==6
99*404b540aSrobert #define DECDPUNMAX 999999
100*404b540aSrobert #elif DECDPUN==7
101*404b540aSrobert #define DECDPUNMAX 9999999
102*404b540aSrobert #elif DECDPUN==8
103*404b540aSrobert #define DECDPUNMAX 99999999
104*404b540aSrobert #elif DECDPUN==9
105*404b540aSrobert #define DECDPUNMAX 999999999
106*404b540aSrobert #elif defined(DECDPUN)
107*404b540aSrobert #error DECDPUN must be in the range 1-9
108*404b540aSrobert #endif
109*404b540aSrobert 
110*404b540aSrobert 
111*404b540aSrobert   /* ----- Shared data ----- */
112*404b540aSrobert   /* The powers of of ten array (powers[n]==10**n, 0<=n<=10) */
113*404b540aSrobert extern const uInt powers[];
114*404b540aSrobert 
115*404b540aSrobert   /* ----- Macros ----- */
116*404b540aSrobert   /* ISZERO -- return true if decNumber dn is a zero */
117*404b540aSrobert   /* [performance-critical in some situations] */
118*404b540aSrobert #define ISZERO(dn) decNumberIsZero(dn)	/* now just a local name */
119*404b540aSrobert 
120*404b540aSrobert   /* X10 and X100 -- multiply integer i by 10 or 100 */
121*404b540aSrobert   /* [shifts are usually faster than multiply; could be conditional] */
122*404b540aSrobert #define X10(i)  (((i)<<1)+((i)<<3))
123*404b540aSrobert #define X100(i) (((i)<<2)+((i)<<5)+((i)<<6))
124*404b540aSrobert 
125*404b540aSrobert   /* D2U -- return the number of Units needed to hold d digits */
126*404b540aSrobert #if DECDPUN==8
127*404b540aSrobert #define D2U(d) ((unsigned)((d)+7)>>3)
128*404b540aSrobert #elif DECDPUN==4
129*404b540aSrobert #define D2U(d) ((unsigned)((d)+3)>>2)
130*404b540aSrobert #else
131*404b540aSrobert #define D2U(d) (((d)+DECDPUN-1)/DECDPUN)
132*404b540aSrobert #endif
133*404b540aSrobert 
134*404b540aSrobert #else
135*404b540aSrobert #error decNumberLocal included more than once
136*404b540aSrobert #endif
137