* Makefile.in: Add empty info, html, dvi, pdf targets.
[official-gcc.git] / libdecnumber / decNumber.h
blob2357fbeab37561b260e728a2191458b339beb649
1 /* Decimal Number module header for the decNumber C Library
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 Contributed by IBM Corporation. Author Mike Cowlishaw.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
22 #if !defined(DECNUMBER)
23 #define DECNUMBER
24 #define DECNAME "decNumber" /* Short name */
25 #define DECVERSION "decNumber 3.24" /* Version [16 max.] */
26 #define DECFULLNAME "Decimal Number Module" /* Verbose name */
27 #define DECAUTHOR "Mike Cowlishaw" /* Who to blame */
29 #if !defined(DECCONTEXT)
30 #include "decContext.h"
31 #endif
34 /* Bit settings for decNumber.bits */
35 #define DECNEG 0x80 /* Sign; 1=negative, 0=positive or zero */
36 #define DECINF 0x40 /* 1=Infinity */
37 #define DECNAN 0x20 /* 1=NaN */
38 #define DECSNAN 0x10 /* 1=sNaN */
39 /* The remaining bits are reserved; they must be 0 */
40 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value */
42 /* DECNUMDIGITS is the default number of digits we can hold in the */
43 /* structure. If undefined, 1 is assumed and it is assumed that the */
44 /* structure will be immediately followed by extra space (if */
45 /* required). DECNUMDIGITS is always >0. */
46 #if !defined(DECNUMDIGITS)
47 #define DECNUMDIGITS 1
48 #endif
51 /* Define the decNumber data structure. The size and shape of the */
52 /* units array in the structure is determined by the following */
53 /* constant. This must not be changed without recompiling the */
54 /* decNumber library modules. */
55 #define DECDPUN 4 /* Decimal Digits Per UNit [must be in */
56 /* range 1-9; power of 2 recommended]. */
57 /* The size (integer data type) of each unit is determined by the */
58 /* number of digits it will hold. */
59 #if DECDPUN<=2
60 #define decNumberUnit uint8_t
61 #elif DECDPUN<=4
62 #define decNumberUnit uint16_t
63 #else
64 #define decNumberUnit uint32_t
65 #endif
66 /* The number of decNumberUnits we need is ceiling of DECNUMDIGITS/DECDPUN */
67 #define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)
69 /* The data structure... */
70 typedef struct
72 int32_t digits; /* Count of digits in the coefficient; >0 */
73 int32_t exponent; /* Unadjusted exponent, unbiased, in */
74 /* range: -1999999997 through 999999999 */
75 uint8_t bits; /* Indicator bits (see above) */
76 decNumberUnit lsu[DECNUMUNITS]; /* Coefficient, from least significant unit */
77 } decNumber;
79 /* Notes: */
80 /* 1. If digits is > DECDPUN then there will be more than one */
81 /* decNumberUnits immediately following the first element of lsu. */
82 /* These contain the remaining (more significant) digits of the */
83 /* number, and may be in the lsu array, or may be guaranteed by */
84 /* some other mechanism (such as being contained in another */
85 /* structure, or being overlaid on dynamically allocated storage). */
86 /* */
87 /* Each integer of the coefficient (except the possibly the last) */
88 /* contains DECDPUN digits (e.g., a value in the range 0 through */
89 /* 99999999 if DECDPUN is 8, or 0 through 9999 if DECDPUN is 4). */
90 /* */
91 /* 2. A decNumber converted to a string may need up to digits+14 */
92 /* characters. The worst cases (non-exponential and exponential */
93 /* formats) are: -0.00000{9...}# */
94 /* and: -9.{9...}E+999999999# (where # is '\0') */
97 /* ------------------------------------------------------------------ */
98 /* decNumber public functions and macros */
99 /* ------------------------------------------------------------------ */
101 #ifdef IN_LIBGCC2
102 #define decNumberFromString __decNumberFromString
103 #define decNumberToString __decNumberToString
104 #define decNumberToEngString __decNumberToEngString
105 #define decNumberAbs __decNumberAbs
106 #define decNumberAdd __decNumberAdd
107 #define decNumberCompare __decNumberCompare
108 #define decNumberDivide __decNumberDivide
109 #define decNumberDivideInteger __decNumberDivideInteger
110 #define decNumberMax __decNumberMax
111 #define decNumberMin __decNumberMin
112 #define decNumberMinus __decNumberMinus
113 #define decNumberMultiply __decNumberMultiply
114 #define decNumberNormalize __decNumberNormalize
115 #define decNumberPlus __decNumberPlus
116 #define decNumberPower __decNumberPower
117 #define decNumberQuantize __decNumberQuantize
118 #define decNumberRemainder __decNumberRemainder
119 #define decNumberRemainderNear __decNumberRemainderNear
120 #define decNumberRescale __decNumberRescale
121 #define decNumberSameQuantum __decNumberSameQuantum
122 #define decNumberSquareRoot __decNumberSquareRoot
123 #define decNumberSubtract __decNumberSubtract
124 #define decNumberToIntegralValue __decNumberToIntegralValue
125 #define decNumberCopy __decNumberCopy
126 #define decNumberTrim __decNumberTrim
127 #define decNumberVersion __decNumberVersion
128 #define decNumberZero __decNumberZero
129 #endif
131 /* Conversions */
132 decNumber *decNumberFromString (decNumber *, const char *, decContext *);
133 char *decNumberToString (const decNumber *, char *);
134 char *decNumberToEngString (const decNumber *, char *);
136 /* Operators */
137 decNumber *decNumberAbs (decNumber *, const decNumber *, decContext *);
138 decNumber *decNumberAdd (decNumber *, const decNumber *,
139 const decNumber *, decContext *);
140 decNumber *decNumberCompare (decNumber *, const decNumber *,
141 const decNumber *, decContext *);
142 decNumber *decNumberDivide (decNumber *, const decNumber *,
143 const decNumber *, decContext *);
144 decNumber *decNumberDivideInteger (decNumber *, const decNumber *,
145 const decNumber *, decContext *);
146 decNumber *decNumberMax (decNumber *, const decNumber *,
147 const decNumber *, decContext *);
148 decNumber *decNumberMin (decNumber *, const decNumber *,
149 const decNumber *, decContext *);
150 decNumber *decNumberMinus (decNumber *, const decNumber *, decContext *);
151 decNumber *decNumberMultiply (decNumber *, const decNumber *,
152 const decNumber *, decContext *);
153 decNumber *decNumberNormalize (decNumber *, const decNumber *, decContext *);
154 decNumber *decNumberPlus (decNumber *, const decNumber *, decContext *);
155 decNumber *decNumberPower (decNumber *, const decNumber *,
156 const decNumber *, decContext *);
157 decNumber *decNumberQuantize (decNumber *, const decNumber *,
158 const decNumber *, decContext *);
159 decNumber *decNumberRemainder (decNumber *, const decNumber *,
160 const decNumber *, decContext *);
161 decNumber *decNumberRemainderNear (decNumber *, const decNumber *,
162 const decNumber *, decContext *);
163 decNumber *decNumberRescale (decNumber *, const decNumber *,
164 const decNumber *, decContext *);
165 decNumber *decNumberSameQuantum (decNumber *, const decNumber *, const decNumber *);
166 decNumber *decNumberSquareRoot (decNumber *, const decNumber *, decContext *);
167 decNumber *decNumberSubtract (decNumber *, const decNumber *,
168 const decNumber *, decContext *);
169 decNumber *decNumberToIntegralValue (decNumber *, const decNumber *, decContext *);
171 /* Utilities */
172 decNumber *decNumberCopy (decNumber *, const decNumber *);
173 decNumber *decNumberTrim (decNumber *);
174 const char *decNumberVersion (void);
175 decNumber *decNumberZero (decNumber *);
177 /* Macros */
178 #define decNumberIsZero(dn) (*(dn)->lsu==0 \
179 && (dn)->digits==1 \
180 && (((dn)->bits&DECSPECIAL)==0))
181 #define decNumberIsNegative(dn) (((dn)->bits&DECNEG)!=0)
182 #define decNumberIsNaN(dn) (((dn)->bits&(DECNAN|DECSNAN))!=0)
183 #define decNumberIsInfinite(dn) (((dn)->bits&DECINF)!=0)
185 #endif