merge from gcc
[deliverable/binutils-gdb.git] / libdecnumber / decContext.h
CommitLineData
f5bc1778
DJ
1/* Decimal context header module for the decNumber C Library.
2 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3 Contributed by IBM Corporation. Author Mike Cowlishaw.
4
5 This file is part of GCC.
6
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.
11
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.)
20
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
24 for more details.
25
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
29 02110-1301, USA. */
30
31/* ------------------------------------------------------------------ */
32/* Decimal Context module header */
33/* ------------------------------------------------------------------ */
34/* */
35/* Context variables must always have valid values: */
36/* */
87d32bb7 37/* status -- [any bits may be cleared, but not set, by user] */
f5bc1778
DJ
38/* round -- must be one of the enumerated rounding modes */
39/* */
40/* The following variables are implied for fixed size formats (i.e., */
41/* they are ignored) but should still be set correctly in case used */
42/* with decNumber functions: */
43/* */
44/* clamp -- must be either 0 or 1 */
45/* digits -- must be in the range 1 through 999999999 */
46/* emax -- must be in the range 0 through 999999999 */
47/* emin -- must be in the range 0 through -999999999 */
48/* extended -- must be either 0 or 1 [present only if DECSUBSET] */
49/* traps -- only defined bits may be set */
50/* */
51/* ------------------------------------------------------------------ */
52
53#if !defined(DECCONTEXT)
54 #define DECCONTEXT
55 #define DECCNAME "decContext" /* Short name */
56 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
87d32bb7 57 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
f5bc1778 58
87d32bb7
DD
59 #if !defined(int32_t)
60 #include <stdint.h> /* C99 standard integers */
61 #endif
f5bc1778 62 #include <stdio.h> /* for printf, etc. */
87d32bb7 63 #include <signal.h> /* for traps */
f5bc1778
DJ
64
65 /* Extended flags setting -- set this to 0 to use only IEEE flags */
87d32bb7 66 #if !defined(DECEXTFLAG)
f5bc1778 67 #define DECEXTFLAG 1 /* 1=enable extended flags */
87d32bb7 68 #endif
f5bc1778
DJ
69
70 /* Conditional code flag -- set this to 0 for best performance */
87d32bb7 71 #if !defined(DECSUBSET)
f5bc1778 72 #define DECSUBSET 0 /* 1=enable subset arithmetic */
87d32bb7 73 #endif
f5bc1778
DJ
74
75 /* Context for operations, with associated constants */
76 enum rounding {
77 DEC_ROUND_CEILING, /* round towards +infinity */
87d32bb7 78 DEC_ROUND_UP, /* round away from 0 */
f5bc1778
DJ
79 DEC_ROUND_HALF_UP, /* 0.5 rounds up */
80 DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
81 DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
82 DEC_ROUND_DOWN, /* round towards 0 (truncate) */
83 DEC_ROUND_FLOOR, /* round towards -infinity */
87d32bb7 84 DEC_ROUND_05UP, /* round for reround */
f5bc1778
DJ
85 DEC_ROUND_MAX /* enum must be less than this */
86 };
87 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
88
89 typedef struct {
87d32bb7
DD
90 int32_t digits; /* working precision */
91 int32_t emax; /* maximum positive exponent */
92 int32_t emin; /* minimum negative exponent */
f5bc1778
DJ
93 enum rounding round; /* rounding mode */
94 uint32_t traps; /* trap-enabler flags */
95 uint32_t status; /* status flags */
96 uint8_t clamp; /* flag: apply IEEE exponent clamp */
97 #if DECSUBSET
98 uint8_t extended; /* flag: special-values allowed */
99 #endif
100 } decContext;
101
102 /* Maxima and Minima for context settings */
103 #define DEC_MAX_DIGITS 999999999
104 #define DEC_MIN_DIGITS 1
105 #define DEC_MAX_EMAX 999999999
106 #define DEC_MIN_EMAX 0
107 #define DEC_MAX_EMIN 0
108 #define DEC_MIN_EMIN -999999999
109 #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
110
87d32bb7
DD
111 /* Classifications for decimal numbers, aligned with 754 (note that */
112 /* 'normal' and 'subnormal' are meaningful only with a decContext */
113 /* or a fixed size format). */
f5bc1778
DJ
114 enum decClass {
115 DEC_CLASS_SNAN,
116 DEC_CLASS_QNAN,
117 DEC_CLASS_NEG_INF,
118 DEC_CLASS_NEG_NORMAL,
119 DEC_CLASS_NEG_SUBNORMAL,
120 DEC_CLASS_NEG_ZERO,
121 DEC_CLASS_POS_ZERO,
122 DEC_CLASS_POS_SUBNORMAL,
123 DEC_CLASS_POS_NORMAL,
124 DEC_CLASS_POS_INF
125 };
126 /* Strings for the decClasses */
127 #define DEC_ClassString_SN "sNaN"
128 #define DEC_ClassString_QN "NaN"
129 #define DEC_ClassString_NI "-Infinity"
130 #define DEC_ClassString_NN "-Normal"
131 #define DEC_ClassString_NS "-Subnormal"
132 #define DEC_ClassString_NZ "-Zero"
133 #define DEC_ClassString_PZ "+Zero"
134 #define DEC_ClassString_PS "+Subnormal"
135 #define DEC_ClassString_PN "+Normal"
136 #define DEC_ClassString_PI "+Infinity"
137 #define DEC_ClassString_UN "Invalid"
138
139 /* Trap-enabler and Status flags (exceptional conditions), and */
140 /* their names. The top byte is reserved for internal use */
141 #if DECEXTFLAG
142 /* Extended flags */
143 #define DEC_Conversion_syntax 0x00000001
144 #define DEC_Division_by_zero 0x00000002
145 #define DEC_Division_impossible 0x00000004
146 #define DEC_Division_undefined 0x00000008
147 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
87d32bb7
DD
148 #define DEC_Inexact 0x00000020
149 #define DEC_Invalid_context 0x00000040
f5bc1778
DJ
150 #define DEC_Invalid_operation 0x00000080
151 #if DECSUBSET
152 #define DEC_Lost_digits 0x00000100
153 #endif
154 #define DEC_Overflow 0x00000200
87d32bb7
DD
155 #define DEC_Clamped 0x00000400
156 #define DEC_Rounded 0x00000800
f5bc1778
DJ
157 #define DEC_Subnormal 0x00001000
158 #define DEC_Underflow 0x00002000
159 #else
160 /* IEEE flags only */
161 #define DEC_Conversion_syntax 0x00000010
162 #define DEC_Division_by_zero 0x00000002
163 #define DEC_Division_impossible 0x00000010
164 #define DEC_Division_undefined 0x00000010
165 #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
87d32bb7
DD
166 #define DEC_Inexact 0x00000001
167 #define DEC_Invalid_context 0x00000010
f5bc1778
DJ
168 #define DEC_Invalid_operation 0x00000010
169 #if DECSUBSET
170 #define DEC_Lost_digits 0x00000000
171 #endif
172 #define DEC_Overflow 0x00000008
87d32bb7
DD
173 #define DEC_Clamped 0x00000000
174 #define DEC_Rounded 0x00000000
f5bc1778
DJ
175 #define DEC_Subnormal 0x00000000
176 #define DEC_Underflow 0x00000004
177 #endif
178
87d32bb7 179 /* IEEE 754 groupings for the flags */
f5bc1778 180 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
87d32bb7
DD
181 /* are not in IEEE 754] */
182 #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
f5bc1778 183 #if DECSUBSET
87d32bb7 184 #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
f5bc1778 185 #else
87d32bb7 186 #define DEC_IEEE_754_Inexact (DEC_Inexact)
f5bc1778 187 #endif
87d32bb7 188 #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
f5bc1778
DJ
189 DEC_Division_impossible | \
190 DEC_Division_undefined | \
191 DEC_Insufficient_storage | \
87d32bb7 192 DEC_Invalid_context | \
f5bc1778 193 DEC_Invalid_operation)
87d32bb7
DD
194 #define DEC_IEEE_754_Overflow (DEC_Overflow)
195 #define DEC_IEEE_754_Underflow (DEC_Underflow)
f5bc1778
DJ
196
197 /* flags which are normally errors (result is qNaN, infinite, or 0) */
87d32bb7
DD
198 #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
199 DEC_IEEE_754_Invalid_operation | \
200 DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
f5bc1778 201 /* flags which cause a result to become qNaN */
87d32bb7 202 #define DEC_NaNs DEC_IEEE_754_Invalid_operation
f5bc1778
DJ
203
204 /* flags which are normally for information only (finite results) */
205 #if DECSUBSET
206 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
207 | DEC_Lost_digits)
208 #else
209 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
210 #endif
211
87d32bb7
DD
212 /* IEEE 854 names (for compatibility with older decNumber versions) */
213 #define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero
214 #define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact
215 #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
216 #define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow
217 #define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow
218
f5bc1778
DJ
219 /* Name strings for the exceptional conditions */
220 #define DEC_Condition_CS "Conversion syntax"
221 #define DEC_Condition_DZ "Division by zero"
222 #define DEC_Condition_DI "Division impossible"
223 #define DEC_Condition_DU "Division undefined"
224 #define DEC_Condition_IE "Inexact"
225 #define DEC_Condition_IS "Insufficient storage"
226 #define DEC_Condition_IC "Invalid context"
227 #define DEC_Condition_IO "Invalid operation"
228 #if DECSUBSET
229 #define DEC_Condition_LD "Lost digits"
230 #endif
231 #define DEC_Condition_OV "Overflow"
232 #define DEC_Condition_PA "Clamped"
233 #define DEC_Condition_RO "Rounded"
234 #define DEC_Condition_SU "Subnormal"
235 #define DEC_Condition_UN "Underflow"
236 #define DEC_Condition_ZE "No status"
237 #define DEC_Condition_MU "Multiple status"
238 #define DEC_Condition_Length 21 /* length of the longest string, */
239 /* including terminator */
240
241 /* Initialization descriptors, used by decContextDefault */
87d32bb7 242 #define DEC_INIT_BASE 0
f5bc1778
DJ
243 #define DEC_INIT_DECIMAL32 32
244 #define DEC_INIT_DECIMAL64 64
245 #define DEC_INIT_DECIMAL128 128
246 /* Synonyms */
247 #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
248 #define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
249 #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
250
251 /* decContext routines */
252
253 #include "decContextSymbols.h"
254
255 extern decContext * decContextClearStatus(decContext *, uint32_t);
256 extern decContext * decContextDefault(decContext *, int32_t);
257 extern enum rounding decContextGetRounding(decContext *);
258 extern uint32_t decContextGetStatus(decContext *);
259 extern decContext * decContextRestoreStatus(decContext *, uint32_t, uint32_t);
260 extern uint32_t decContextSaveStatus(decContext *, uint32_t);
261 extern decContext * decContextSetRounding(decContext *, enum rounding);
262 extern decContext * decContextSetStatus(decContext *, uint32_t);
263 extern decContext * decContextSetStatusFromString(decContext *, const char *);
264 extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
265 extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
266 extern const char * decContextStatusToString(const decContext *);
87d32bb7 267 extern int32_t decContextTestEndian(uint8_t);
f5bc1778
DJ
268 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
269 extern uint32_t decContextTestStatus(decContext *, uint32_t);
270 extern decContext * decContextZeroStatus(decContext *);
271
272#endif
This page took 0.100037 seconds and 4 git commands to generate.