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
12 In addition to the permissions in the GNU General Public License,
13 the Free Software Foundation gives you unlimited permission to link
14 the compiled version of this file into combinations with other
15 programs, and to distribute those combinations without any
16 restriction coming from the use of this file. (The General Public
17 License restrictions do apply in other respects; for example, they
18 cover modification of the file, and distribution when not linked
19 into a combine executable.)
21 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22 WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 You should have received a copy of the GNU General Public License
27 along with GCC; see the file COPYING. If not, write to the Free
28 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
31 #if !defined(DECNUMBER)
33 #define DECNAME "decNumber" /* Short name */
34 #define DECVERSION "decNumber 3.24" /* Version [16 max.] */
35 #define DECFULLNAME "Decimal Number Module" /* Verbose name */
36 #define DECAUTHOR "Mike Cowlishaw" /* Who to blame */
38 #if !defined(DECCONTEXT)
39 #include "decContext.h"
43 /* Bit settings for decNumber.bits */
44 #define DECNEG 0x80 /* Sign; 1=negative, 0=positive or zero */
45 #define DECINF 0x40 /* 1=Infinity */
46 #define DECNAN 0x20 /* 1=NaN */
47 #define DECSNAN 0x10 /* 1=sNaN */
48 /* The remaining bits are reserved; they must be 0 */
49 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value */
51 /* DECNUMDIGITS is the default number of digits we can hold in the */
52 /* structure. If undefined, 1 is assumed and it is assumed that the */
53 /* structure will be immediately followed by extra space (if */
54 /* required). DECNUMDIGITS is always >0. */
55 #if !defined(DECNUMDIGITS)
56 #define DECNUMDIGITS 1
60 /* Define the decNumber data structure. The size and shape of the */
61 /* units array in the structure is determined by the following */
62 /* constant. This must not be changed without recompiling the */
63 /* decNumber library modules. */
64 #define DECDPUN 4 /* Decimal Digits Per UNit [must be in */
65 /* range 1-9; power of 2 recommended]. */
66 /* The size (integer data type) of each unit is determined by the */
67 /* number of digits it will hold. */
69 #define decNumberUnit uint8_t
71 #define decNumberUnit uint16_t
73 #define decNumberUnit uint32_t
75 /* The number of decNumberUnits we need is ceiling of DECNUMDIGITS/DECDPUN */
76 #define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)
78 /* The data structure... */
81 int32_t digits
; /* Count of digits in the coefficient; >0 */
82 int32_t exponent
; /* Unadjusted exponent, unbiased, in */
83 /* range: -1999999997 through 999999999 */
84 uint8_t bits
; /* Indicator bits (see above) */
85 decNumberUnit lsu
[DECNUMUNITS
]; /* Coefficient, from least significant unit */
89 /* 1. If digits is > DECDPUN then there will be more than one */
90 /* decNumberUnits immediately following the first element of lsu. */
91 /* These contain the remaining (more significant) digits of the */
92 /* number, and may be in the lsu array, or may be guaranteed by */
93 /* some other mechanism (such as being contained in another */
94 /* structure, or being overlaid on dynamically allocated storage). */
96 /* Each integer of the coefficient (except the possibly the last) */
97 /* contains DECDPUN digits (e.g., a value in the range 0 through */
98 /* 99999999 if DECDPUN is 8, or 0 through 9999 if DECDPUN is 4). */
100 /* 2. A decNumber converted to a string may need up to digits+14 */
101 /* characters. The worst cases (non-exponential and exponential */
102 /* formats) are: -0.00000{9...}# */
103 /* and: -9.{9...}E+999999999# (where # is '\0') */
106 /* ------------------------------------------------------------------ */
107 /* decNumber public functions and macros */
108 /* ------------------------------------------------------------------ */
111 #define decNumberFromString __decNumberFromString
112 #define decNumberToString __decNumberToString
113 #define decNumberToEngString __decNumberToEngString
114 #define decNumberAbs __decNumberAbs
115 #define decNumberAdd __decNumberAdd
116 #define decNumberCompare __decNumberCompare
117 #define decNumberDivide __decNumberDivide
118 #define decNumberDivideInteger __decNumberDivideInteger
119 #define decNumberMax __decNumberMax
120 #define decNumberMin __decNumberMin
121 #define decNumberMinus __decNumberMinus
122 #define decNumberMultiply __decNumberMultiply
123 #define decNumberNormalize __decNumberNormalize
124 #define decNumberPlus __decNumberPlus
125 #define decNumberPower __decNumberPower
126 #define decNumberQuantize __decNumberQuantize
127 #define decNumberRemainder __decNumberRemainder
128 #define decNumberRemainderNear __decNumberRemainderNear
129 #define decNumberRescale __decNumberRescale
130 #define decNumberSameQuantum __decNumberSameQuantum
131 #define decNumberSquareRoot __decNumberSquareRoot
132 #define decNumberSubtract __decNumberSubtract
133 #define decNumberToIntegralValue __decNumberToIntegralValue
134 #define decNumberCopy __decNumberCopy
135 #define decNumberTrim __decNumberTrim
136 #define decNumberVersion __decNumberVersion
137 #define decNumberZero __decNumberZero
141 decNumber
*decNumberFromString (decNumber
*, const char *, decContext
*);
142 char *decNumberToString (const decNumber
*, char *);
143 char *decNumberToEngString (const decNumber
*, char *);
146 decNumber
*decNumberAbs (decNumber
*, const decNumber
*, decContext
*);
147 decNumber
*decNumberAdd (decNumber
*, const decNumber
*,
148 const decNumber
*, decContext
*);
149 decNumber
*decNumberCompare (decNumber
*, const decNumber
*,
150 const decNumber
*, decContext
*);
151 decNumber
*decNumberDivide (decNumber
*, const decNumber
*,
152 const decNumber
*, decContext
*);
153 decNumber
*decNumberDivideInteger (decNumber
*, const decNumber
*,
154 const decNumber
*, decContext
*);
155 decNumber
*decNumberMax (decNumber
*, const decNumber
*,
156 const decNumber
*, decContext
*);
157 decNumber
*decNumberMin (decNumber
*, const decNumber
*,
158 const decNumber
*, decContext
*);
159 decNumber
*decNumberMinus (decNumber
*, const decNumber
*, decContext
*);
160 decNumber
*decNumberMultiply (decNumber
*, const decNumber
*,
161 const decNumber
*, decContext
*);
162 decNumber
*decNumberNormalize (decNumber
*, const decNumber
*, decContext
*);
163 decNumber
*decNumberPlus (decNumber
*, const decNumber
*, decContext
*);
164 decNumber
*decNumberPower (decNumber
*, const decNumber
*,
165 const decNumber
*, decContext
*);
166 decNumber
*decNumberQuantize (decNumber
*, const decNumber
*,
167 const decNumber
*, decContext
*);
168 decNumber
*decNumberRemainder (decNumber
*, const decNumber
*,
169 const decNumber
*, decContext
*);
170 decNumber
*decNumberRemainderNear (decNumber
*, const decNumber
*,
171 const decNumber
*, decContext
*);
172 decNumber
*decNumberRescale (decNumber
*, const decNumber
*,
173 const decNumber
*, decContext
*);
174 decNumber
*decNumberSameQuantum (decNumber
*, const decNumber
*, const decNumber
*);
175 decNumber
*decNumberSquareRoot (decNumber
*, const decNumber
*, decContext
*);
176 decNumber
*decNumberSubtract (decNumber
*, const decNumber
*,
177 const decNumber
*, decContext
*);
178 decNumber
*decNumberToIntegralValue (decNumber
*, const decNumber
*, decContext
*);
181 decNumber
*decNumberCopy (decNumber
*, const decNumber
*);
182 decNumber
*decNumberTrim (decNumber
*);
183 const char *decNumberVersion (void);
184 decNumber
*decNumberZero (decNumber
*);
187 #define decNumberIsZero(dn) (*(dn)->lsu==0 \
189 && (((dn)->bits&DECSPECIAL)==0))
190 #define decNumberIsNegative(dn) (((dn)->bits&DECNEG)!=0)
191 #define decNumberIsNaN(dn) (((dn)->bits&(DECNAN|DECSNAN))!=0)
192 #define decNumberIsInfinite(dn) (((dn)->bits&DECINF)!=0)