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