1 /* Decimal Context 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 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
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
22 /* ------------------------------------------------------------------ */
24 /* Context must always be set correctly: */
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] */
35 /* ------------------------------------------------------------------ */
37 #if !defined(DECCONTEXT)
39 #define DECCNAME "decContext" /* Short name */
40 #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
41 #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
44 #include <stdint.h> /* C99 standard integers */
46 #include <signal.h> /* for traps */
49 /* Conditional code flag -- set this to 0 for best performance */
50 #define DECSUBSET 0 /* 1 to enable subset arithmetic */
52 /* Context for operations, with associated constants */
55 DEC_ROUND_CEILING
, /* round towards +infinity */
56 DEC_ROUND_UP
, /* round away from 0 */
57 DEC_ROUND_HALF_UP
, /* 0.5 rounds up */
58 DEC_ROUND_HALF_EVEN
, /* 0.5 rounds to nearest even */
59 DEC_ROUND_HALF_DOWN
, /* 0.5 rounds down */
60 DEC_ROUND_DOWN
, /* round towards 0 (truncate) */
61 DEC_ROUND_FLOOR
, /* round towards -infinity */
62 DEC_ROUND_MAX
/* enum must be less than this */
67 int32_t digits
; /* working precision */
68 int32_t emax
; /* maximum positive exponent */
69 int32_t emin
; /* minimum negative exponent */
70 enum rounding round
; /* rounding mode */
71 uint32_t traps
; /* trap-enabler flags */
72 uint32_t status
; /* status flags */
73 uint8_t clamp
; /* flag: apply IEEE exponent clamp */
75 uint8_t extended
; /* flag: special-values allowed */
79 /* Maxima and Minima */
80 #define DEC_MAX_DIGITS 999999999
81 #define DEC_MIN_DIGITS 1
82 #define DEC_MAX_EMAX 999999999
83 #define DEC_MIN_EMAX 0
84 #define DEC_MAX_EMIN 0
85 #define DEC_MIN_EMIN -999999999
87 /* Trap-enabler and Status flags (exceptional conditions), and their names */
88 /* Top byte is reserved for internal use */
89 #define DEC_Conversion_syntax 0x00000001
90 #define DEC_Division_by_zero 0x00000002
91 #define DEC_Division_impossible 0x00000004
92 #define DEC_Division_undefined 0x00000008
93 #define DEC_Insufficient_storage 0x00000010 /* [used if malloc fails] */
94 #define DEC_Inexact 0x00000020
95 #define DEC_Invalid_context 0x00000040
96 #define DEC_Invalid_operation 0x00000080
98 #define DEC_Lost_digits 0x00000100
100 #define DEC_Overflow 0x00000200
101 #define DEC_Clamped 0x00000400
102 #define DEC_Rounded 0x00000800
103 #define DEC_Subnormal 0x00001000
104 #define DEC_Underflow 0x00002000
106 /* IEEE 854 groupings for the flags */
107 /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal are */
108 /* not in IEEE 854] */
109 #define DEC_IEEE_854_Division_by_zero (DEC_Division_by_zero)
111 #define DEC_IEEE_854_Inexact (DEC_Inexact | DEC_Lost_digits)
113 #define DEC_IEEE_854_Inexact (DEC_Inexact)
115 #define DEC_IEEE_854_Invalid_operation (DEC_Conversion_syntax | \
116 DEC_Division_impossible | \
117 DEC_Division_undefined | \
118 DEC_Insufficient_storage | \
119 DEC_Invalid_context | \
120 DEC_Invalid_operation)
121 #define DEC_IEEE_854_Overflow (DEC_Overflow)
122 #define DEC_IEEE_854_Underflow (DEC_Underflow)
124 /* flags which are normally errors (results are qNaN, infinite, or 0) */
125 #define DEC_Errors (DEC_IEEE_854_Division_by_zero | \
126 DEC_IEEE_854_Invalid_operation | \
127 DEC_IEEE_854_Overflow | DEC_IEEE_854_Underflow)
128 /* flags which cause a result to become qNaN */
129 #define DEC_NaNs DEC_IEEE_854_Invalid_operation
131 /* flags which are normally for information only (have finite results) */
133 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
136 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
139 /* name strings for the exceptional conditions */
141 #define DEC_Condition_CS "Conversion syntax"
142 #define DEC_Condition_DZ "Division by zero"
143 #define DEC_Condition_DI "Division impossible"
144 #define DEC_Condition_DU "Division undefined"
145 #define DEC_Condition_IE "Inexact"
146 #define DEC_Condition_IS "Insufficient storage"
147 #define DEC_Condition_IC "Invalid context"
148 #define DEC_Condition_IO "Invalid operation"
150 #define DEC_Condition_LD "Lost digits"
152 #define DEC_Condition_OV "Overflow"
153 #define DEC_Condition_PA "Clamped"
154 #define DEC_Condition_RO "Rounded"
155 #define DEC_Condition_SU "Subnormal"
156 #define DEC_Condition_UN "Underflow"
157 #define DEC_Condition_ZE "No status"
158 #define DEC_Condition_MU "Multiple status"
159 #define DEC_Condition_Length 21 /* length of the longest string, */
160 /* including terminator */
162 /* Initialization descriptors, used by decContextDefault */
163 #define DEC_INIT_BASE 0
164 #define DEC_INIT_DECIMAL32 32
165 #define DEC_INIT_DECIMAL64 64
166 #define DEC_INIT_DECIMAL128 128
168 /* decContext routines */
170 #define decContextDefault __decContextDefault
171 #define decContextSetStatus __decContextSetStatus
172 #define decContextStatusToString __decContextStatusToString
173 #define decContextSetStatusFromString __decContextSetStatusFromString
175 decContext
*decContextDefault (decContext
*, int32_t);
176 decContext
*decContextSetStatus (decContext
*, uint32_t);
177 const char *decContextStatusToString (decContext
*);
178 decContext
*decContextSetStatusFromString (decContext
*, char *);