* Makefile.in (TEXI_GCCINSTALL_FILES): Add gcc-vers.texi dependency.
[official-gcc.git] / libdecnumber / decContext.h
blob41c4b52a4003bfbd1d7f4fb17e5eb48b6e6d3720
1 /* Decimal Context module header for the decNumber C Library
2 Copyright (C) 2005, 2006 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 /* ------------------------------------------------------------------ */
23 /* */
24 /* Context must always be set correctly: */
25 /* */
26 /* digits -- must be in the range 1 through 999999999 */
27 /* emax -- must be in the range 0 through 999999999 */
28 /* emin -- must be in the range 0 through -999999999 */
29 /* round -- must be one of the enumerated rounding modes */
30 /* traps -- only defined bits may be set */
31 /* status -- [any bits may be cleared, but not set, by user] */
32 /* clamp -- must be either 0 or 1 */
33 /* extended -- must be either 0 or 1 [present only if DECSUBSET] */
34 /* */
35 /* ------------------------------------------------------------------ */
37 #if !defined(DECCONTEXT)
38 #define DECCONTEXT
39 #define DECCNAME "decContext" /* Short name */
40 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
41 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
43 #include "gstdint.h" /* C99 standard integers */
44 #include <signal.h> /* for traps */
47 /* Conditional code flag -- set this to 0 for best performance */
48 #define DECSUBSET 0 /* 1 to enable subset arithmetic */
50 /* Context for operations, with associated constants */
51 enum rounding
53 DEC_ROUND_CEILING, /* round towards +infinity */
54 DEC_ROUND_UP, /* round away from 0 */
55 DEC_ROUND_HALF_UP, /* 0.5 rounds up */
56 DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
57 DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
58 DEC_ROUND_DOWN, /* round towards 0 (truncate) */
59 DEC_ROUND_FLOOR, /* round towards -infinity */
60 DEC_ROUND_MAX /* enum must be less than this */
63 typedef struct
65 int32_t digits; /* working precision */
66 int32_t emax; /* maximum positive exponent */
67 int32_t emin; /* minimum negative exponent */
68 enum rounding round; /* rounding mode */
69 uint32_t traps; /* trap-enabler flags */
70 uint32_t status; /* status flags */
71 uint8_t clamp; /* flag: apply IEEE exponent clamp */
72 #if DECSUBSET
73 uint8_t extended; /* flag: special-values allowed */
74 #endif
75 } decContext;
77 /* Maxima and Minima */
78 #define DEC_MAX_DIGITS 999999999
79 #define DEC_MIN_DIGITS 1
80 #define DEC_MAX_EMAX 999999999
81 #define DEC_MIN_EMAX 0
82 #define DEC_MAX_EMIN 0
83 #define DEC_MIN_EMIN -999999999
85 /* Trap-enabler and Status flags (exceptional conditions), and their names */
86 /* Top byte is reserved for internal use */
87 #define DEC_Conversion_syntax 0x00000001
88 #define DEC_Division_by_zero 0x00000002
89 #define DEC_Division_impossible 0x00000004
90 #define DEC_Division_undefined 0x00000008
91 #define DEC_Insufficient_storage 0x00000010 /* [used if malloc fails] */
92 #define DEC_Inexact 0x00000020
93 #define DEC_Invalid_context 0x00000040
94 #define DEC_Invalid_operation 0x00000080
95 #if DECSUBSET
96 #define DEC_Lost_digits 0x00000100
97 #endif
98 #define DEC_Overflow 0x00000200
99 #define DEC_Clamped 0x00000400
100 #define DEC_Rounded 0x00000800
101 #define DEC_Subnormal 0x00001000
102 #define DEC_Underflow 0x00002000
104 /* IEEE 854 groupings for the flags */
105 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal are */
106 /* not in IEEE 854] */
107 #define DEC_IEEE_854_Division_by_zero (DEC_Division_by_zero)
108 #if DECSUBSET
109 #define DEC_IEEE_854_Inexact (DEC_Inexact | DEC_Lost_digits)
110 #else
111 #define DEC_IEEE_854_Inexact (DEC_Inexact)
112 #endif
113 #define DEC_IEEE_854_Invalid_operation (DEC_Conversion_syntax | \
114 DEC_Division_impossible | \
115 DEC_Division_undefined | \
116 DEC_Insufficient_storage | \
117 DEC_Invalid_context | \
118 DEC_Invalid_operation)
119 #define DEC_IEEE_854_Overflow (DEC_Overflow)
120 #define DEC_IEEE_854_Underflow (DEC_Underflow)
122 /* flags which are normally errors (results are qNaN, infinite, or 0) */
123 #define DEC_Errors (DEC_IEEE_854_Division_by_zero | \
124 DEC_IEEE_854_Invalid_operation | \
125 DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow)
126 /* flags which cause a result to become qNaN */
127 #define DEC_NaNs DEC_IEEE_854_Invalid_operation
129 /* flags which are normally for information only (have finite results) */
130 #if DECSUBSET
131 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
132 | DEC_Lost_digits)
133 #else
134 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
135 #endif
137 /* name strings for the exceptional conditions */
139 #define DEC_Condition_CS "Conversion syntax"
140 #define DEC_Condition_DZ "Division by zero"
141 #define DEC_Condition_DI "Division impossible"
142 #define DEC_Condition_DU "Division undefined"
143 #define DEC_Condition_IE "Inexact"
144 #define DEC_Condition_IS "Insufficient storage"
145 #define DEC_Condition_IC "Invalid context"
146 #define DEC_Condition_IO "Invalid operation"
147 #if DECSUBSET
148 #define DEC_Condition_LD "Lost digits"
149 #endif
150 #define DEC_Condition_OV "Overflow"
151 #define DEC_Condition_PA "Clamped"
152 #define DEC_Condition_RO "Rounded"
153 #define DEC_Condition_SU "Subnormal"
154 #define DEC_Condition_UN "Underflow"
155 #define DEC_Condition_ZE "No status"
156 #define DEC_Condition_MU "Multiple status"
157 #define DEC_Condition_Length 21 /* length of the longest string, */
158 /* including terminator */
160 /* Initialization descriptors, used by decContextDefault */
161 #define DEC_INIT_BASE 0
162 #define DEC_INIT_DECIMAL32 32
163 #define DEC_INIT_DECIMAL64 64
164 #define DEC_INIT_DECIMAL128 128
166 /* decContext routines */
167 #ifdef IN_LIBGCC2
168 #define decContextDefault __decContextDefault
169 #define decContextSetStatus __decContextSetStatus
170 #define decContextStatusToString __decContextStatusToString
171 #define decContextSetStatusFromString __decContextSetStatusFromString
172 #endif
173 decContext *decContextDefault (decContext *, int32_t);
174 decContext *decContextSetStatus (decContext *, uint32_t);
175 const char *decContextStatusToString (const decContext *);
176 decContext *decContextSetStatusFromString (decContext *, const char *);
178 #endif