2005-01-20 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / libdecnumber / decNumber.h
bloba4c45d0305299a8f7961c802ec07879d18a464f2
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 *, char *, decContext *);
133 char *decNumberToString (decNumber *, char *);
134 char *decNumberToEngString (decNumber *, char *);
136 /* Operators */
137 decNumber *decNumberAbs (decNumber *, decNumber *, decContext *);
138 decNumber *decNumberAdd (decNumber *, decNumber *, decNumber *, decContext *);
139 decNumber *decNumberCompare (decNumber *, decNumber *, decNumber *,
140 decContext *);
141 decNumber *decNumberDivide (decNumber *, decNumber *, decNumber *,
142 decContext *);
143 decNumber *decNumberDivideInteger (decNumber *, decNumber *, decNumber *,
144 decContext *);
145 decNumber *decNumberMax (decNumber *, decNumber *, decNumber *, decContext *);
146 decNumber *decNumberMin (decNumber *, decNumber *, decNumber *, decContext *);
147 decNumber *decNumberMinus (decNumber *, decNumber *, decContext *);
148 decNumber *decNumberMultiply (decNumber *, decNumber *, decNumber *,
149 decContext *);
150 decNumber *decNumberNormalize (decNumber *, decNumber *, decContext *);
151 decNumber *decNumberPlus (decNumber *, decNumber *, decContext *);
152 decNumber *decNumberPower (decNumber *, decNumber *, decNumber *,
153 decContext *);
154 decNumber *decNumberQuantize (decNumber *, decNumber *, decNumber *,
155 decContext *);
156 decNumber *decNumberRemainder (decNumber *, decNumber *, decNumber *,
157 decContext *);
158 decNumber *decNumberRemainderNear (decNumber *, decNumber *, decNumber *,
159 decContext *);
160 decNumber *decNumberRescale (decNumber *, decNumber *, decNumber *,
161 decContext *);
162 decNumber *decNumberSameQuantum (decNumber *, decNumber *, decNumber *);
163 decNumber *decNumberSquareRoot (decNumber *, decNumber *, decContext *);
164 decNumber *decNumberSubtract (decNumber *, decNumber *, decNumber *,
165 decContext *);
166 decNumber *decNumberToIntegralValue (decNumber *, decNumber *, decContext *);
168 /* Utilities */
169 decNumber *decNumberCopy (decNumber *, decNumber *);
170 decNumber *decNumberTrim (decNumber *);
171 const char *decNumberVersion (void);
172 decNumber *decNumberZero (decNumber *);
174 /* Macros */
175 #define decNumberIsZero(dn) (*(dn)->lsu==0 \
176 && (dn)->digits==1 \
177 && (((dn)->bits&DECSPECIAL)==0))
178 #define decNumberIsNegative(dn) (((dn)->bits&DECNEG)!=0)
179 #define decNumberIsNaN(dn) (((dn)->bits&(DECNAN|DECSNAN))!=0)
180 #define decNumberIsInfinite(dn) (((dn)->bits&DECINF)!=0)
181 #define decNumberNegate(dn) (((dn)->bits)^=DECNEG)
183 #endif