dec_number 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/README +20 -0
  2. data/dec_number.gemspec +13 -0
  3. data/ext/dec_number/Gemfile +4 -0
  4. data/ext/dec_number/NOTES +10 -0
  5. data/ext/dec_number/decNumber/ICU-license.html +45 -0
  6. data/ext/dec_number/decNumber/Makefile.am +3 -0
  7. data/ext/dec_number/decNumber/Makefile.in +680 -0
  8. data/ext/dec_number/decNumber/aclocal.m4 +8988 -0
  9. data/ext/dec_number/decNumber/autom4te.cache/output.0 +5107 -0
  10. data/ext/dec_number/decNumber/autom4te.cache/output.1 +6026 -0
  11. data/ext/dec_number/decNumber/autom4te.cache/output.2 +13468 -0
  12. data/ext/dec_number/decNumber/autom4te.cache/output.3 +13472 -0
  13. data/ext/dec_number/decNumber/autom4te.cache/requests +407 -0
  14. data/ext/dec_number/decNumber/autom4te.cache/traces.0 +352 -0
  15. data/ext/dec_number/decNumber/autom4te.cache/traces.1 +772 -0
  16. data/ext/dec_number/decNumber/autom4te.cache/traces.2 +591 -0
  17. data/ext/dec_number/decNumber/autom4te.cache/traces.3 +2362 -0
  18. data/ext/dec_number/decNumber/config.guess +1501 -0
  19. data/ext/dec_number/decNumber/config.h.in +142 -0
  20. data/ext/dec_number/decNumber/config.sub +1705 -0
  21. data/ext/dec_number/decNumber/configure +13468 -0
  22. data/ext/dec_number/decNumber/configure.ac +36 -0
  23. data/ext/dec_number/decNumber/decBasic.c +3908 -0
  24. data/ext/dec_number/decNumber/decCommon.c +1835 -0
  25. data/ext/dec_number/decNumber/decContext.c +437 -0
  26. data/ext/dec_number/decNumber/decContext.h +254 -0
  27. data/ext/dec_number/decNumber/decDPD.h +1185 -0
  28. data/ext/dec_number/decNumber/decDouble.c +140 -0
  29. data/ext/dec_number/decNumber/decDouble.h +155 -0
  30. data/ext/dec_number/decNumber/decNumber.c +8141 -0
  31. data/ext/dec_number/decNumber/decNumber.h +182 -0
  32. data/ext/dec_number/decNumber/decNumberLocal.h +757 -0
  33. data/ext/dec_number/decNumber/decPacked.c +220 -0
  34. data/ext/dec_number/decNumber/decPacked.h +52 -0
  35. data/ext/dec_number/decNumber/decQuad.c +135 -0
  36. data/ext/dec_number/decNumber/decQuad.h +177 -0
  37. data/ext/dec_number/decNumber/decSingle.c +71 -0
  38. data/ext/dec_number/decNumber/decSingle.h +86 -0
  39. data/ext/dec_number/decNumber/decimal128.c +553 -0
  40. data/ext/dec_number/decNumber/decimal128.h +81 -0
  41. data/ext/dec_number/decNumber/decimal32.c +476 -0
  42. data/ext/dec_number/decNumber/decimal32.h +81 -0
  43. data/ext/dec_number/decNumber/decimal64.c +839 -0
  44. data/ext/dec_number/decNumber/decimal64.h +83 -0
  45. data/ext/dec_number/decNumber/decnumber.pdf +0 -0
  46. data/ext/dec_number/decNumber/depcomp +630 -0
  47. data/ext/dec_number/decNumber/example1.c +38 -0
  48. data/ext/dec_number/decNumber/example2.c +52 -0
  49. data/ext/dec_number/decNumber/example3.c +64 -0
  50. data/ext/dec_number/decNumber/example4.c +61 -0
  51. data/ext/dec_number/decNumber/example5.c +36 -0
  52. data/ext/dec_number/decNumber/example6.c +61 -0
  53. data/ext/dec_number/decNumber/example7.c +35 -0
  54. data/ext/dec_number/decNumber/example8.c +39 -0
  55. data/ext/dec_number/decNumber/install-sh +520 -0
  56. data/ext/dec_number/decNumber/libdecNumber.a +0 -0
  57. data/ext/dec_number/decNumber/ltmain.sh +8745 -0
  58. data/ext/dec_number/decNumber/missing +376 -0
  59. data/ext/dec_number/decNumber/readme.txt +81 -0
  60. data/ext/dec_number/dec_number.c +464 -0
  61. data/ext/dec_number/extconf.rb +52 -0
  62. data/ext/dec_number/extconf2.rb +50 -0
  63. data/ext/dec_number/recompile.sh +3 -0
  64. data/ext/dec_number/test_dec_number.rb +236 -0
  65. data/ext/dec_number/test_numeric.rb +235 -0
  66. metadata +111 -0
@@ -0,0 +1,254 @@
1
+ /* ------------------------------------------------------------------ */
2
+ /* Decimal Context module header */
3
+ /* ------------------------------------------------------------------ */
4
+ /* Copyright (c) IBM Corporation, 2000, 2010. All rights reserved. */
5
+ /* */
6
+ /* This software is made available under the terms of the */
7
+ /* ICU License -- ICU 1.8.1 and later. */
8
+ /* */
9
+ /* The description and User's Guide ("The decNumber C Library") for */
10
+ /* this software is called decNumber.pdf. This document is */
11
+ /* available, together with arithmetic and format specifications, */
12
+ /* testcases, and Web links, on the General Decimal Arithmetic page. */
13
+ /* */
14
+ /* Please send comments, suggestions, and corrections to the author: */
15
+ /* mfc@uk.ibm.com */
16
+ /* Mike Cowlishaw, IBM Fellow */
17
+ /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
18
+ /* ------------------------------------------------------------------ */
19
+ /* */
20
+ /* Context variables must always have valid values: */
21
+ /* */
22
+ /* status -- [any bits may be cleared, but not set, by user] */
23
+ /* round -- must be one of the enumerated rounding modes */
24
+ /* */
25
+ /* The following variables are implied for fixed size formats (i.e., */
26
+ /* they are ignored) but should still be set correctly in case used */
27
+ /* with decNumber functions: */
28
+ /* */
29
+ /* clamp -- must be either 0 or 1 */
30
+ /* digits -- must be in the range 1 through 999999999 */
31
+ /* emax -- must be in the range 0 through 999999999 */
32
+ /* emin -- must be in the range 0 through -999999999 */
33
+ /* extended -- must be either 0 or 1 [present only if DECSUBSET] */
34
+ /* traps -- only defined bits may be set */
35
+ /* */
36
+ /* ------------------------------------------------------------------ */
37
+
38
+ #if !defined(DECCONTEXT)
39
+ #define DECCONTEXT
40
+ #define DECCNAME "decContext" /* Short name */
41
+ #define DECCFULLNAME "Decimal Context Descriptor" /* Verbose name */
42
+ #define DECCAUTHOR "Mike Cowlishaw" /* Who to blame */
43
+
44
+ #if !defined(int32_t)
45
+ #include <stdint.h> /* C99 standard integers */
46
+ #endif
47
+ #include <stdio.h> /* for printf, etc. */
48
+ #include <signal.h> /* for traps */
49
+
50
+ /* Extended flags setting -- set this to 0 to use only IEEE flags */
51
+ #if !defined(DECEXTFLAG)
52
+ #define DECEXTFLAG 1 /* 1=enable extended flags */
53
+ #endif
54
+
55
+ /* Conditional code flag -- set this to 0 for best performance */
56
+ #if !defined(DECSUBSET)
57
+ #define DECSUBSET 0 /* 1=enable subset arithmetic */
58
+ #endif
59
+
60
+ /* Context for operations, with associated constants */
61
+ enum rounding {
62
+ DEC_ROUND_CEILING, /* round towards +infinity */
63
+ DEC_ROUND_UP, /* round away from 0 */
64
+ DEC_ROUND_HALF_UP, /* 0.5 rounds up */
65
+ DEC_ROUND_HALF_EVEN, /* 0.5 rounds to nearest even */
66
+ DEC_ROUND_HALF_DOWN, /* 0.5 rounds down */
67
+ DEC_ROUND_DOWN, /* round towards 0 (truncate) */
68
+ DEC_ROUND_FLOOR, /* round towards -infinity */
69
+ DEC_ROUND_05UP, /* round for reround */
70
+ DEC_ROUND_MAX /* enum must be less than this */
71
+ };
72
+ #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
73
+
74
+ typedef struct {
75
+ int32_t digits; /* working precision */
76
+ int32_t emax; /* maximum positive exponent */
77
+ int32_t emin; /* minimum negative exponent */
78
+ enum rounding round; /* rounding mode */
79
+ uint32_t traps; /* trap-enabler flags */
80
+ uint32_t status; /* status flags */
81
+ uint8_t clamp; /* flag: apply IEEE exponent clamp */
82
+ #if DECSUBSET
83
+ uint8_t extended; /* flag: special-values allowed */
84
+ #endif
85
+ } decContext;
86
+
87
+ /* Maxima and Minima for context settings */
88
+ #define DEC_MAX_DIGITS 999999999
89
+ #define DEC_MIN_DIGITS 1
90
+ #define DEC_MAX_EMAX 999999999
91
+ #define DEC_MIN_EMAX 0
92
+ #define DEC_MAX_EMIN 0
93
+ #define DEC_MIN_EMIN -999999999
94
+ #define DEC_MAX_MATH 999999 /* max emax, etc., for math funcs. */
95
+
96
+ /* Classifications for decimal numbers, aligned with 754 (note that */
97
+ /* 'normal' and 'subnormal' are meaningful only with a decContext */
98
+ /* or a fixed size format). */
99
+ enum decClass {
100
+ DEC_CLASS_SNAN,
101
+ DEC_CLASS_QNAN,
102
+ DEC_CLASS_NEG_INF,
103
+ DEC_CLASS_NEG_NORMAL,
104
+ DEC_CLASS_NEG_SUBNORMAL,
105
+ DEC_CLASS_NEG_ZERO,
106
+ DEC_CLASS_POS_ZERO,
107
+ DEC_CLASS_POS_SUBNORMAL,
108
+ DEC_CLASS_POS_NORMAL,
109
+ DEC_CLASS_POS_INF
110
+ };
111
+ /* Strings for the decClasses */
112
+ #define DEC_ClassString_SN "sNaN"
113
+ #define DEC_ClassString_QN "NaN"
114
+ #define DEC_ClassString_NI "-Infinity"
115
+ #define DEC_ClassString_NN "-Normal"
116
+ #define DEC_ClassString_NS "-Subnormal"
117
+ #define DEC_ClassString_NZ "-Zero"
118
+ #define DEC_ClassString_PZ "+Zero"
119
+ #define DEC_ClassString_PS "+Subnormal"
120
+ #define DEC_ClassString_PN "+Normal"
121
+ #define DEC_ClassString_PI "+Infinity"
122
+ #define DEC_ClassString_UN "Invalid"
123
+
124
+ /* Trap-enabler and Status flags (exceptional conditions), and */
125
+ /* their names. The top byte is reserved for internal use */
126
+ #if DECEXTFLAG
127
+ /* Extended flags */
128
+ #define DEC_Conversion_syntax 0x00000001
129
+ #define DEC_Division_by_zero 0x00000002
130
+ #define DEC_Division_impossible 0x00000004
131
+ #define DEC_Division_undefined 0x00000008
132
+ #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
133
+ #define DEC_Inexact 0x00000020
134
+ #define DEC_Invalid_context 0x00000040
135
+ #define DEC_Invalid_operation 0x00000080
136
+ #if DECSUBSET
137
+ #define DEC_Lost_digits 0x00000100
138
+ #endif
139
+ #define DEC_Overflow 0x00000200
140
+ #define DEC_Clamped 0x00000400
141
+ #define DEC_Rounded 0x00000800
142
+ #define DEC_Subnormal 0x00001000
143
+ #define DEC_Underflow 0x00002000
144
+ #else
145
+ /* IEEE flags only */
146
+ #define DEC_Conversion_syntax 0x00000010
147
+ #define DEC_Division_by_zero 0x00000002
148
+ #define DEC_Division_impossible 0x00000010
149
+ #define DEC_Division_undefined 0x00000010
150
+ #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails] */
151
+ #define DEC_Inexact 0x00000001
152
+ #define DEC_Invalid_context 0x00000010
153
+ #define DEC_Invalid_operation 0x00000010
154
+ #if DECSUBSET
155
+ #define DEC_Lost_digits 0x00000000
156
+ #endif
157
+ #define DEC_Overflow 0x00000008
158
+ #define DEC_Clamped 0x00000000
159
+ #define DEC_Rounded 0x00000000
160
+ #define DEC_Subnormal 0x00000000
161
+ #define DEC_Underflow 0x00000004
162
+ #endif
163
+
164
+ /* IEEE 754 groupings for the flags */
165
+ /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal */
166
+ /* are not in IEEE 754] */
167
+ #define DEC_IEEE_754_Division_by_zero (DEC_Division_by_zero)
168
+ #if DECSUBSET
169
+ #define DEC_IEEE_754_Inexact (DEC_Inexact | DEC_Lost_digits)
170
+ #else
171
+ #define DEC_IEEE_754_Inexact (DEC_Inexact)
172
+ #endif
173
+ #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax | \
174
+ DEC_Division_impossible | \
175
+ DEC_Division_undefined | \
176
+ DEC_Insufficient_storage | \
177
+ DEC_Invalid_context | \
178
+ DEC_Invalid_operation)
179
+ #define DEC_IEEE_754_Overflow (DEC_Overflow)
180
+ #define DEC_IEEE_754_Underflow (DEC_Underflow)
181
+
182
+ /* flags which are normally errors (result is qNaN, infinite, or 0) */
183
+ #define DEC_Errors (DEC_IEEE_754_Division_by_zero | \
184
+ DEC_IEEE_754_Invalid_operation | \
185
+ DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
186
+ /* flags which cause a result to become qNaN */
187
+ #define DEC_NaNs DEC_IEEE_754_Invalid_operation
188
+
189
+ /* flags which are normally for information only (finite results) */
190
+ #if DECSUBSET
191
+ #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact \
192
+ | DEC_Lost_digits)
193
+ #else
194
+ #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
195
+ #endif
196
+
197
+ /* IEEE 854 names (for compatibility with older decNumber versions) */
198
+ #define DEC_IEEE_854_Division_by_zero DEC_IEEE_754_Division_by_zero
199
+ #define DEC_IEEE_854_Inexact DEC_IEEE_754_Inexact
200
+ #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
201
+ #define DEC_IEEE_854_Overflow DEC_IEEE_754_Overflow
202
+ #define DEC_IEEE_854_Underflow DEC_IEEE_754_Underflow
203
+
204
+ /* Name strings for the exceptional conditions */
205
+ #define DEC_Condition_CS "Conversion syntax"
206
+ #define DEC_Condition_DZ "Division by zero"
207
+ #define DEC_Condition_DI "Division impossible"
208
+ #define DEC_Condition_DU "Division undefined"
209
+ #define DEC_Condition_IE "Inexact"
210
+ #define DEC_Condition_IS "Insufficient storage"
211
+ #define DEC_Condition_IC "Invalid context"
212
+ #define DEC_Condition_IO "Invalid operation"
213
+ #if DECSUBSET
214
+ #define DEC_Condition_LD "Lost digits"
215
+ #endif
216
+ #define DEC_Condition_OV "Overflow"
217
+ #define DEC_Condition_PA "Clamped"
218
+ #define DEC_Condition_RO "Rounded"
219
+ #define DEC_Condition_SU "Subnormal"
220
+ #define DEC_Condition_UN "Underflow"
221
+ #define DEC_Condition_ZE "No status"
222
+ #define DEC_Condition_MU "Multiple status"
223
+ #define DEC_Condition_Length 21 /* length of the longest string, */
224
+ /* including terminator */
225
+
226
+ /* Initialization descriptors, used by decContextDefault */
227
+ #define DEC_INIT_BASE 0
228
+ #define DEC_INIT_DECIMAL32 32
229
+ #define DEC_INIT_DECIMAL64 64
230
+ #define DEC_INIT_DECIMAL128 128
231
+ /* Synonyms */
232
+ #define DEC_INIT_DECSINGLE DEC_INIT_DECIMAL32
233
+ #define DEC_INIT_DECDOUBLE DEC_INIT_DECIMAL64
234
+ #define DEC_INIT_DECQUAD DEC_INIT_DECIMAL128
235
+
236
+ /* decContext routines */
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 int32_t decContextTestEndian(uint8_t);
250
+ extern uint32_t decContextTestSavedStatus(uint32_t, uint32_t);
251
+ extern uint32_t decContextTestStatus(decContext *, uint32_t);
252
+ extern decContext * decContextZeroStatus(decContext *);
253
+
254
+ #endif