00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #if !defined(DECCONTEXT)
00041 #define DECCONTEXT
00042 #define DECCNAME "decContext"
00043 #define DECCFULLNAME "Decimal Context Descriptor"
00044 #define DECCAUTHOR "Mike Cowlishaw"
00045
00046 #if !defined(int32_t)
00047 #include <stdint.h>
00048 #endif
00049 #include <stdio.h>
00050 #include <signal.h>
00051
00052
00053 #if !defined(DECEXTFLAG)
00054 #define DECEXTFLAG 1
00055 #endif
00056
00057
00058 #if !defined(DECSUBSET)
00059 #define DECSUBSET 0
00060 #endif
00061
00062
00063 enum rounding {
00064 DEC_ROUND_CEILING,
00065 DEC_ROUND_UP,
00066 DEC_ROUND_HALF_UP,
00067 DEC_ROUND_HALF_EVEN,
00068 DEC_ROUND_HALF_DOWN,
00069 DEC_ROUND_DOWN,
00070 DEC_ROUND_FLOOR,
00071 DEC_ROUND_05UP,
00072 DEC_ROUND_MAX
00073 };
00074 #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
00075
00076 typedef struct {
00077 int32_t digits;
00078 int32_t emax;
00079 int32_t emin;
00080 enum rounding round;
00081 uint32_t traps;
00082 uint32_t status;
00083 uint8_t clamp;
00084 #if DECSUBSET
00085 uint8_t extended;
00086 #endif
00087 } decContext;
00088
00089
00090 #define DEC_MAX_DIGITS 999999999
00091 #define DEC_MIN_DIGITS 1
00092 #define DEC_MAX_EMAX 999999999
00093 #define DEC_MIN_EMAX 0
00094 #define DEC_MAX_EMIN 0
00095 #define DEC_MIN_EMIN -999999999
00096 #define DEC_MAX_MATH 999999
00097
00098
00099
00100
00101 enum decClass {
00102 DEC_CLASS_SNAN,
00103 DEC_CLASS_QNAN,
00104 DEC_CLASS_NEG_INF,
00105 DEC_CLASS_NEG_NORMAL,
00106 DEC_CLASS_NEG_SUBNORMAL,
00107 DEC_CLASS_NEG_ZERO,
00108 DEC_CLASS_POS_ZERO,
00109 DEC_CLASS_POS_SUBNORMAL,
00110 DEC_CLASS_POS_NORMAL,
00111 DEC_CLASS_POS_INF
00112 };
00113
00114 #define DEC_ClassString_SN "sNaN"
00115 #define DEC_ClassString_QN "NaN"
00116 #define DEC_ClassString_NI "-Infinity"
00117 #define DEC_ClassString_NN "-Normal"
00118 #define DEC_ClassString_NS "-Subnormal"
00119 #define DEC_ClassString_NZ "-Zero"
00120 #define DEC_ClassString_PZ "+Zero"
00121 #define DEC_ClassString_PS "+Subnormal"
00122 #define DEC_ClassString_PN "+Normal"
00123 #define DEC_ClassString_PI "+Infinity"
00124 #define DEC_ClassString_UN "Invalid"
00125
00126
00127
00128 #if DECEXTFLAG
00129
00130 #define DEC_Conversion_syntax 0x00000001
00131 #define DEC_Division_by_zero 0x00000002
00132 #define DEC_Division_impossible 0x00000004
00133 #define DEC_Division_undefined 0x00000008
00134 #define DEC_Insufficient_storage 0x00000010
00135 #define DEC_Inexact 0x00000020
00136 #define DEC_Invalid_context 0x00000040
00137 #define DEC_Invalid_operation 0x00000080
00138 #if DECSUBSET
00139 #define DEC_Lost_digits 0x00000100
00140 #endif
00141 #define DEC_Overflow 0x00000200
00142 #define DEC_Clamped 0x00000400
00143 #define DEC_Rounded 0x00000800
00144 #define DEC_Subnormal 0x00001000
00145 #define DEC_Underflow 0x00002000
00146 #else
00147
00148 #define DEC_Conversion_syntax 0x00000010
00149 #define DEC_Division_by_zero 0x00000002
00150 #define DEC_Division_impossible 0x00000010
00151 #define DEC_Division_undefined 0x00000010
00152 #define DEC_Insufficient_storage 0x00000010
00153 #define DEC_Inexact 0x00000001
00154 #define DEC_Invalid_context 0x00000010
00155 #define DEC_Invalid_operation 0x00000010
00156 #if DECSUBSET
00157 #define DEC_Lost_digits 0x00000000
00158 #endif
00159 #define DEC_Overflow 0x00000008
00160 #define DEC_Clamped 0x00000000
00161 #define DEC_Rounded 0x00000000
00162 #define DEC_Subnormal 0x00000000
00163 #define DEC_Underflow 0x00000004
00164 #endif
00165
00166
00167
00168
00169 #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
00170 #if DECSUBSET
00171 #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
00172 #else
00173 #define DEC_IEEE_754_Inexact (DEC_Inexact)
00174 #endif
00175 #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
00176 DEC_Division_impossible | \
00177 DEC_Division_undefined | \
00178 DEC_Insufficient_storage | \
00179 DEC_Invalid_context | \
00180 DEC_Invalid_operation)
00181 #define DEC_IEEE_754_Overflow (DEC_Overflow)
00182 #define DEC_IEEE_754_Underflow (DEC_Underflow)
00183
00184
00185 #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
00186 DEC_IEEE_754_Invalid_operation | \
00187 DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
00188
00189 #define DEC_NaNs DEC_IEEE_754_Invalid_operation
00190
00191
00192 #if DECSUBSET
00193 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
00194 | DEC_Lost_digits)
00195 #else
00196 #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
00197 #endif
00198
00199
00200 #define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero
00201 #define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact
00202 #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
00203 #define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow
00204 #define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow
00205
00206
00207 #define DEC_Condition_CS "Conversion syntax"
00208 #define DEC_Condition_DZ "Division by zero"
00209 #define DEC_Condition_DI "Division impossible"
00210 #define DEC_Condition_DU "Division undefined"
00211 #define DEC_Condition_IE "Inexact"
00212 #define DEC_Condition_IS "Insufficient storage"
00213 #define DEC_Condition_IC "Invalid context"
00214 #define DEC_Condition_IO "Invalid operation"
00215 #if DECSUBSET
00216 #define DEC_Condition_LD "Lost digits"
00217 #endif
00218 #define DEC_Condition_OV "Overflow"
00219 #define DEC_Condition_PA "Clamped"
00220 #define DEC_Condition_RO "Rounded"
00221 #define DEC_Condition_SU "Subnormal"
00222 #define DEC_Condition_UN "Underflow"
00223 #define DEC_Condition_ZE "No status"
00224 #define DEC_Condition_MU "Multiple status"
00225 #define DEC_Condition_Length 21
00226
00227
00228
00229 #define DEC_INIT_BASE 0
00230 #define DEC_INIT_DECIMAL32 32
00231 #define DEC_INIT_DECIMAL64 64
00232 #define DEC_INIT_DECIMAL128 128
00233
00234 #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
00235 #define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
00236 #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
00237
00238
00239 extern decContext * decContextClearStatus(decContext *, uint32_t);
00240 extern decContext * decContextDefault(decContext *, int32_t);
00241 extern enum rounding decContextGetRounding(decContext *);
00242 extern uint32_t decContextGetStatus(decContext *);
00243 extern decContext * decContextRestoreStatus(decContext *, uint32_t, uint32_t);
00244 extern uint32_t decContextSaveStatus(decContext *, uint32_t);
00245 extern decContext * decContextSetRounding(decContext *, enum rounding);
00246 extern decContext * decContextSetStatus(decContext *, uint32_t);
00247 extern decContext * decContextSetStatusFromString(decContext *, const char *);
00248 extern decContext * decContextSetStatusFromStringQuiet(decContext *, const char *);
00249 extern decContext * decContextSetStatusQuiet(decContext *, uint32_t);
00250 extern const char * decContextStatusToString(const decContext *);
00251 extern int32_t decContextTestEndian(uint8_t);
00252 extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
00253 extern uint32_t decContextTestStatus(decContext *, uint32_t);
00254 extern decContext * decContextZeroStatus(decContext *);
00255
00256 #endif