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,220 @@
1
+ /* ------------------------------------------------------------------ */
2
+ /* Packed Decimal conversion module */
3
+ /* ------------------------------------------------------------------ */
4
+ /* Copyright (c) IBM Corporation, 2000, 2002. 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
+ /* This module comprises the routines for Packed Decimal format */
20
+ /* numbers. Conversions are supplied to and from decNumber, which in */
21
+ /* turn supports: */
22
+ /* conversions to and from string */
23
+ /* arithmetic routines */
24
+ /* utilities. */
25
+ /* Conversions from decNumber to and from densely packed decimal */
26
+ /* formats are provided by the decimal32 through decimal128 modules. */
27
+ /* ------------------------------------------------------------------ */
28
+
29
+ #include <string.h> // for NULL
30
+ #include "decNumber.h" // base number library
31
+ #include "decPacked.h" // packed decimal
32
+ #include "decNumberLocal.h" // decNumber local types, etc.
33
+
34
+ /* ------------------------------------------------------------------ */
35
+ /* decPackedFromNumber -- convert decNumber to BCD Packed Decimal */
36
+ /* */
37
+ /* bcd is the BCD bytes */
38
+ /* length is the length of the BCD array */
39
+ /* scale is the scale result */
40
+ /* dn is the decNumber */
41
+ /* returns bcd, or NULL if error */
42
+ /* */
43
+ /* The number is converted to a BCD packed decimal byte array, */
44
+ /* right aligned in the bcd array, whose length is indicated by the */
45
+ /* second parameter. The final 4-bit nibble in the array will be a */
46
+ /* sign nibble, C (1100) for + and D (1101) for -. Unused bytes and */
47
+ /* nibbles to the left of the number are set to 0. */
48
+ /* */
49
+ /* scale is set to the scale of the number (this is the exponent, */
50
+ /* negated). To force the number to a specified scale, first use the */
51
+ /* decNumberRescale routine, which will round and change the exponent */
52
+ /* as necessary. */
53
+ /* */
54
+ /* If there is an error (that is, the decNumber has too many digits */
55
+ /* to fit in length bytes, or it is a NaN or Infinity), NULL is */
56
+ /* returned and the bcd and scale results are unchanged. Otherwise */
57
+ /* bcd is returned. */
58
+ /* ------------------------------------------------------------------ */
59
+ uByte * decPackedFromNumber(uByte *bcd, Int length, Int *scale,
60
+ const decNumber *dn) {
61
+ const Unit *up=dn->lsu; // Unit array pointer
62
+ uByte obyte, *out; // current output byte, and where it goes
63
+ Int indigs=dn->digits; // digits processed
64
+ uInt cut=DECDPUN; // downcounter per Unit
65
+ uInt u=*up; // work
66
+ uInt nib; // ..
67
+ #if DECDPUN<=4
68
+ uInt temp; // ..
69
+ #endif
70
+
71
+ if (dn->digits>length*2-1 // too long ..
72
+ ||(dn->bits & DECSPECIAL)) return NULL; // .. or special -- hopeless
73
+
74
+ if (dn->bits&DECNEG) obyte=DECPMINUS; // set the sign ..
75
+ else obyte=DECPPLUS;
76
+ *scale=-dn->exponent; // .. and scale
77
+
78
+ // loop from lowest (rightmost) byte
79
+ out=bcd+length-1; // -> final byte
80
+ for (; out>=bcd; out--) {
81
+ if (indigs>0) {
82
+ if (cut==0) {
83
+ up++;
84
+ u=*up;
85
+ cut=DECDPUN;
86
+ }
87
+ #if DECDPUN<=4
88
+ temp=(u*6554)>>16; // fast /10
89
+ nib=u-X10(temp);
90
+ u=temp;
91
+ #else
92
+ nib=u%10; // cannot use *6554 trick :-(
93
+ u=u/10;
94
+ #endif
95
+ obyte|=(nib<<4);
96
+ indigs--;
97
+ cut--;
98
+ }
99
+ *out=obyte;
100
+ obyte=0; // assume 0
101
+ if (indigs>0) {
102
+ if (cut==0) {
103
+ up++;
104
+ u=*up;
105
+ cut=DECDPUN;
106
+ }
107
+ #if DECDPUN<=4
108
+ temp=(u*6554)>>16; // as above
109
+ obyte=(uByte)(u-X10(temp));
110
+ u=temp;
111
+ #else
112
+ obyte=(uByte)(u%10);
113
+ u=u/10;
114
+ #endif
115
+ indigs--;
116
+ cut--;
117
+ }
118
+ } // loop
119
+
120
+ return bcd;
121
+ } // decPackedFromNumber
122
+
123
+ /* ------------------------------------------------------------------ */
124
+ /* decPackedToNumber -- convert BCD Packed Decimal to a decNumber */
125
+ /* */
126
+ /* bcd is the BCD bytes */
127
+ /* length is the length of the BCD array */
128
+ /* scale is the scale associated with the BCD integer */
129
+ /* dn is the decNumber [with space for length*2 digits] */
130
+ /* returns dn, or NULL if error */
131
+ /* */
132
+ /* The BCD packed decimal byte array, together with an associated */
133
+ /* scale, is converted to a decNumber. The BCD array is assumed full */
134
+ /* of digits, and must be ended by a 4-bit sign nibble in the least */
135
+ /* significant four bits of the final byte. */
136
+ /* */
137
+ /* The scale is used (negated) as the exponent of the decNumber. */
138
+ /* Note that zeros may have a sign and/or a scale. */
139
+ /* */
140
+ /* The decNumber structure is assumed to have sufficient space to */
141
+ /* hold the converted number (that is, up to length*2-1 digits), so */
142
+ /* no error is possible unless the adjusted exponent is out of range, */
143
+ /* no sign nibble was found, or a sign nibble was found before the */
144
+ /* final nibble. In these error cases, NULL is returned and the */
145
+ /* decNumber will be 0. */
146
+ /* ------------------------------------------------------------------ */
147
+ decNumber * decPackedToNumber(const uByte *bcd, Int length,
148
+ const Int *scale, decNumber *dn) {
149
+ const uByte *last=bcd+length-1; // -> last byte
150
+ const uByte *first; // -> first non-zero byte
151
+ uInt nib; // work nibble
152
+ Unit *up=dn->lsu; // output pointer
153
+ Int digits; // digits count
154
+ Int cut=0; // phase of output
155
+
156
+ decNumberZero(dn); // default result
157
+ last=&bcd[length-1];
158
+ nib=*last & 0x0f; // get the sign
159
+ if (nib==DECPMINUS || nib==DECPMINUSALT) dn->bits=DECNEG;
160
+ else if (nib<=9) return NULL; // not a sign nibble
161
+
162
+ // skip leading zero bytes [final byte is always non-zero, due to sign]
163
+ for (first=bcd; *first==0;) first++;
164
+ digits=(last-first)*2+1; // calculate digits ..
165
+ if ((*first & 0xf0)==0) digits--; // adjust for leading zero nibble
166
+ if (digits!=0) dn->digits=digits; // count of actual digits [if 0,
167
+ // leave as 1]
168
+
169
+ // check the adjusted exponent; note that scale could be unbounded
170
+ dn->exponent=-*scale; // set the exponent
171
+ if (*scale>=0) { // usual case
172
+ if ((dn->digits-*scale-1)<-DECNUMMAXE) { // underflow
173
+ decNumberZero(dn);
174
+ return NULL;}
175
+ }
176
+ else { // -ve scale; +ve exponent
177
+ // need to be careful to avoid wrap, here, also BADINT case
178
+ if ((*scale<-DECNUMMAXE) // overflow even without digits
179
+ || ((dn->digits-*scale-1)>DECNUMMAXE)) { // overflow
180
+ decNumberZero(dn);
181
+ return NULL;}
182
+ }
183
+ if (digits==0) return dn; // result was zero
184
+
185
+ // copy the digits to the number's units, starting at the lsu
186
+ // [unrolled]
187
+ for (;;) { // forever
188
+ // left nibble first
189
+ nib=(unsigned)(*last & 0xf0)>>4;
190
+ // got a digit, in nib
191
+ if (nib>9) {decNumberZero(dn); return NULL;}
192
+
193
+ if (cut==0) *up=(Unit)nib;
194
+ else *up=(Unit)(*up+nib*DECPOWERS[cut]);
195
+ digits--;
196
+ if (digits==0) break; // got them all
197
+ cut++;
198
+ if (cut==DECDPUN) {
199
+ up++;
200
+ cut=0;
201
+ }
202
+ last--; // ready for next
203
+ nib=*last & 0x0f; // get right nibble
204
+ if (nib>9) {decNumberZero(dn); return NULL;}
205
+
206
+ // got a digit, in nib
207
+ if (cut==0) *up=(Unit)nib;
208
+ else *up=(Unit)(*up+nib*DECPOWERS[cut]);
209
+ digits--;
210
+ if (digits==0) break; // got them all
211
+ cut++;
212
+ if (cut==DECDPUN) {
213
+ up++;
214
+ cut=0;
215
+ }
216
+ } // forever
217
+
218
+ return dn;
219
+ } // decPackedToNumber
220
+
@@ -0,0 +1,52 @@
1
+ /* ------------------------------------------------------------------ */
2
+ /* Packed Decimal conversion module header */
3
+ /* ------------------------------------------------------------------ */
4
+ /* Copyright (c) IBM Corporation, 2000, 2005. 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
+ #if !defined(DECPACKED)
21
+ #define DECPACKED
22
+ #define DECPNAME "decPacked" /* Short name */
23
+ #define DECPFULLNAME "Packed Decimal conversions" /* Verbose name */
24
+ #define DECPAUTHOR "Mike Cowlishaw" /* Who to blame */
25
+
26
+ #define DECPACKED_DefP 32 /* default precision */
27
+
28
+ #ifndef DECNUMDIGITS
29
+ #define DECNUMDIGITS DECPACKED_DefP /* size if not already defined*/
30
+ #endif
31
+ #include "decNumber.h" /* context and number library */
32
+
33
+ /* Sign nibble constants */
34
+ #if !defined(DECPPLUSALT)
35
+ #define DECPPLUSALT 0x0A /* alternate plus nibble */
36
+ #define DECPMINUSALT 0x0B /* alternate minus nibble */
37
+ #define DECPPLUS 0x0C /* preferred plus nibble */
38
+ #define DECPMINUS 0x0D /* preferred minus nibble */
39
+ #define DECPPLUSALT2 0x0E /* alternate plus nibble */
40
+ #define DECPUNSIGNED 0x0F /* alternate plus nibble (unsigned) */
41
+ #endif
42
+
43
+ /* ---------------------------------------------------------------- */
44
+ /* decPacked public routines */
45
+ /* ---------------------------------------------------------------- */
46
+ /* Conversions */
47
+ uint8_t * decPackedFromNumber(uint8_t *, int32_t, int32_t *,
48
+ const decNumber *);
49
+ decNumber * decPackedToNumber(const uint8_t *, int32_t, const int32_t *,
50
+ decNumber *);
51
+
52
+ #endif
@@ -0,0 +1,135 @@
1
+ /* ------------------------------------------------------------------ */
2
+ /* decQuad.c -- decQuad operations module */
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 included in the package as decNumber.pdf. This */
11
+ /* document is also available in HTML, together with 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
+ /* This module comprises decQuad operations (including conversions) */
20
+ /* ------------------------------------------------------------------ */
21
+
22
+
23
+ /* Constant mappings for shared code */
24
+ #define DECPMAX DECQUAD_Pmax
25
+ #define DECEMIN DECQUAD_Emin
26
+ #define DECEMAX DECQUAD_Emax
27
+ #define DECEMAXD DECQUAD_EmaxD
28
+ #define DECBYTES DECQUAD_Bytes
29
+ #define DECSTRING DECQUAD_String
30
+ #define DECECONL DECQUAD_EconL
31
+ #define DECBIAS DECQUAD_Bias
32
+ #define DECLETS DECQUAD_Declets
33
+ #define DECQTINY (-DECQUAD_Bias)
34
+
35
+ /* Type and function mappings for shared code */
36
+ #define decFloat decQuad // Type name
37
+
38
+ // Utilities and conversions (binary results, extractors, etc.)
39
+ #define decFloatFromBCD decQuadFromBCD
40
+ #define decFloatFromInt32 decQuadFromInt32
41
+ #define decFloatFromPacked decQuadFromPacked
42
+ #define decFloatFromPackedChecked decQuadFromPackedChecked
43
+ #define decFloatFromString decQuadFromString
44
+ #define decFloatFromUInt32 decQuadFromUInt32
45
+ #define decFloatFromWider decQuadFromWider
46
+ #define decFloatGetCoefficient decQuadGetCoefficient
47
+ #define decFloatGetExponent decQuadGetExponent
48
+ #define decFloatSetCoefficient decQuadSetCoefficient
49
+ #define decFloatSetExponent decQuadSetExponent
50
+ #define decFloatShow decQuadShow
51
+ #define decFloatToBCD decQuadToBCD
52
+ #define decFloatToEngString decQuadToEngString
53
+ #define decFloatToInt32 decQuadToInt32
54
+ #define decFloatToInt32Exact decQuadToInt32Exact
55
+ #define decFloatToPacked decQuadToPacked
56
+ #define decFloatToString decQuadToString
57
+ #define decFloatToUInt32 decQuadToUInt32
58
+ #define decFloatToUInt32Exact decQuadToUInt32Exact
59
+ #define decFloatToWider decQuadToWider
60
+ #define decFloatZero decQuadZero
61
+
62
+ // Computational (result is a decFloat)
63
+ #define decFloatAbs decQuadAbs
64
+ #define decFloatAdd decQuadAdd
65
+ #define decFloatAnd decQuadAnd
66
+ #define decFloatDivide decQuadDivide
67
+ #define decFloatDivideInteger decQuadDivideInteger
68
+ #define decFloatFMA decQuadFMA
69
+ #define decFloatInvert decQuadInvert
70
+ #define decFloatLogB decQuadLogB
71
+ #define decFloatMax decQuadMax
72
+ #define decFloatMaxMag decQuadMaxMag
73
+ #define decFloatMin decQuadMin
74
+ #define decFloatMinMag decQuadMinMag
75
+ #define decFloatMinus decQuadMinus
76
+ #define decFloatMultiply decQuadMultiply
77
+ #define decFloatNextMinus decQuadNextMinus
78
+ #define decFloatNextPlus decQuadNextPlus
79
+ #define decFloatNextToward decQuadNextToward
80
+ #define decFloatOr decQuadOr
81
+ #define decFloatPlus decQuadPlus
82
+ #define decFloatQuantize decQuadQuantize
83
+ #define decFloatReduce decQuadReduce
84
+ #define decFloatRemainder decQuadRemainder
85
+ #define decFloatRemainderNear decQuadRemainderNear
86
+ #define decFloatRotate decQuadRotate
87
+ #define decFloatScaleB decQuadScaleB
88
+ #define decFloatShift decQuadShift
89
+ #define decFloatSubtract decQuadSubtract
90
+ #define decFloatToIntegralValue decQuadToIntegralValue
91
+ #define decFloatToIntegralExact decQuadToIntegralExact
92
+ #define decFloatXor decQuadXor
93
+
94
+ // Comparisons
95
+ #define decFloatCompare decQuadCompare
96
+ #define decFloatCompareSignal decQuadCompareSignal
97
+ #define decFloatCompareTotal decQuadCompareTotal
98
+ #define decFloatCompareTotalMag decQuadCompareTotalMag
99
+
100
+ // Copies
101
+ #define decFloatCanonical decQuadCanonical
102
+ #define decFloatCopy decQuadCopy
103
+ #define decFloatCopyAbs decQuadCopyAbs
104
+ #define decFloatCopyNegate decQuadCopyNegate
105
+ #define decFloatCopySign decQuadCopySign
106
+
107
+ // Non-computational
108
+ #define decFloatClass decQuadClass
109
+ #define decFloatClassString decQuadClassString
110
+ #define decFloatDigits decQuadDigits
111
+ #define decFloatIsCanonical decQuadIsCanonical
112
+ #define decFloatIsFinite decQuadIsFinite
113
+ #define decFloatIsInfinite decQuadIsInfinite
114
+ #define decFloatIsInteger decQuadIsInteger
115
+ #define decFloatIsLogical decQuadIsLogical
116
+ #define decFloatIsNaN decQuadIsNaN
117
+ #define decFloatIsNegative decQuadIsNegative
118
+ #define decFloatIsNormal decQuadIsNormal
119
+ #define decFloatIsPositive decQuadIsPositive
120
+ #define decFloatIsSignaling decQuadIsSignaling
121
+ #define decFloatIsSignalling decQuadIsSignalling
122
+ #define decFloatIsSigned decQuadIsSigned
123
+ #define decFloatIsSubnormal decQuadIsSubnormal
124
+ #define decFloatIsZero decQuadIsZero
125
+ #define decFloatRadix decQuadRadix
126
+ #define decFloatSameQuantum decQuadSameQuantum
127
+ #define decFloatVersion decQuadVersion
128
+
129
+ /* And now the code itself */
130
+ #include "decContext.h" // public includes
131
+ #include "decQuad.h" // ..
132
+ #include "decNumberLocal.h" // local includes (need DECPMAX)
133
+ #include "decCommon.c" // non-arithmetic decFloat routines
134
+ #include "decBasic.c" // basic formats routines
135
+
@@ -0,0 +1,177 @@
1
+ /* ------------------------------------------------------------------ */
2
+ /* decQuad.h -- Decimal 128-bit format 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 included in the package as decNumber.pdf. This */
11
+ /* document is also available in HTML, together with 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
+ /* This include file is always included by decSingle and decDouble, */
20
+ /* and therefore also holds useful constants used by all three. */
21
+
22
+ #if !defined(DECQUAD)
23
+ #define DECQUAD
24
+
25
+ #define DECQUADNAME "decimalQuad" /* Short name */
26
+ #define DECQUADTITLE "Decimal 128-bit datum" /* Verbose name */
27
+ #define DECQUADAUTHOR "Mike Cowlishaw" /* Who to blame */
28
+
29
+ /* parameters for decQuads */
30
+ #define DECQUAD_Bytes 16 /* length */
31
+ #define DECQUAD_Pmax 34 /* maximum precision (digits) */
32
+ #define DECQUAD_Emin -6143 /* minimum adjusted exponent */
33
+ #define DECQUAD_Emax 6144 /* maximum adjusted exponent */
34
+ #define DECQUAD_EmaxD 4 /* maximum exponent digits */
35
+ #define DECQUAD_Bias 6176 /* bias for the exponent */
36
+ #define DECQUAD_String 43 /* maximum string length, +1 */
37
+ #define DECQUAD_EconL 12 /* exponent continuation length */
38
+ #define DECQUAD_Declets 11 /* count of declets */
39
+ /* highest biased exponent (Elimit-1) */
40
+ #define DECQUAD_Ehigh (DECQUAD_Emax + DECQUAD_Bias - (DECQUAD_Pmax-1))
41
+
42
+ /* Required include */
43
+ #include "decContext.h"
44
+
45
+ /* The decQuad decimal 128-bit type, accessible by all sizes */
46
+ typedef union {
47
+ uint8_t bytes[DECQUAD_Bytes]; /* fields: 1, 5, 12, 110 bits */
48
+ uint16_t shorts[DECQUAD_Bytes/2];
49
+ uint32_t words[DECQUAD_Bytes/4];
50
+ #if DECUSE64
51
+ uint64_t longs[DECQUAD_Bytes/8];
52
+ #endif
53
+ } decQuad;
54
+
55
+ /* ---------------------------------------------------------------- */
56
+ /* Shared constants */
57
+ /* ---------------------------------------------------------------- */
58
+
59
+ /* sign and special values [top 32-bits; last two bits are don't-care
60
+ for Infinity on input, last bit don't-care for NaNs] */
61
+ #define DECFLOAT_Sign 0x80000000 /* 1 00000 00 Sign */
62
+ #define DECFLOAT_NaN 0x7c000000 /* 0 11111 00 NaN generic */
63
+ #define DECFLOAT_qNaN 0x7c000000 /* 0 11111 00 qNaN */
64
+ #define DECFLOAT_sNaN 0x7e000000 /* 0 11111 10 sNaN */
65
+ #define DECFLOAT_Inf 0x78000000 /* 0 11110 00 Infinity */
66
+ #define DECFLOAT_MinSp 0x78000000 /* minimum special value */
67
+ /* [specials are all >=MinSp] */
68
+ /* Sign nibble constants */
69
+ #if !defined(DECPPLUSALT)
70
+ #define DECPPLUSALT 0x0A /* alternate plus nibble */
71
+ #define DECPMINUSALT 0x0B /* alternate minus nibble */
72
+ #define DECPPLUS 0x0C /* preferred plus nibble */
73
+ #define DECPMINUS 0x0D /* preferred minus nibble */
74
+ #define DECPPLUSALT2 0x0E /* alternate plus nibble */
75
+ #define DECPUNSIGNED 0x0F /* alternate plus nibble (unsigned) */
76
+ #endif
77
+
78
+ /* ---------------------------------------------------------------- */
79
+ /* Routines -- implemented as decFloat routines in common files */
80
+ /* ---------------------------------------------------------------- */
81
+
82
+ /* Utilities and conversions, extractors, etc.) */
83
+ extern decQuad * decQuadFromBCD(decQuad *, int32_t, const uint8_t *, int32_t);
84
+ extern decQuad * decQuadFromInt32(decQuad *, int32_t);
85
+ extern decQuad * decQuadFromPacked(decQuad *, int32_t, const uint8_t *);
86
+ extern decQuad * decQuadFromPackedChecked(decQuad *, int32_t, const uint8_t *);
87
+ extern decQuad * decQuadFromString(decQuad *, const char *, decContext *);
88
+ extern decQuad * decQuadFromUInt32(decQuad *, uint32_t);
89
+ extern int32_t decQuadGetCoefficient(const decQuad *, uint8_t *);
90
+ extern int32_t decQuadGetExponent(const decQuad *);
91
+ extern decQuad * decQuadSetCoefficient(decQuad *, const uint8_t *, int32_t);
92
+ extern decQuad * decQuadSetExponent(decQuad *, decContext *, int32_t);
93
+ extern void decQuadShow(const decQuad *, const char *);
94
+ extern int32_t decQuadToBCD(const decQuad *, int32_t *, uint8_t *);
95
+ extern char * decQuadToEngString(const decQuad *, char *);
96
+ extern int32_t decQuadToInt32(const decQuad *, decContext *, enum rounding);
97
+ extern int32_t decQuadToInt32Exact(const decQuad *, decContext *, enum rounding);
98
+ extern int32_t decQuadToPacked(const decQuad *, int32_t *, uint8_t *);
99
+ extern char * decQuadToString(const decQuad *, char *);
100
+ extern uint32_t decQuadToUInt32(const decQuad *, decContext *, enum rounding);
101
+ extern uint32_t decQuadToUInt32Exact(const decQuad *, decContext *, enum rounding);
102
+ extern decQuad * decQuadZero(decQuad *);
103
+
104
+ /* Computational (result is a decQuad) */
105
+ extern decQuad * decQuadAbs(decQuad *, const decQuad *, decContext *);
106
+ extern decQuad * decQuadAdd(decQuad *, const decQuad *, const decQuad *, decContext *);
107
+ extern decQuad * decQuadAnd(decQuad *, const decQuad *, const decQuad *, decContext *);
108
+ extern decQuad * decQuadDivide(decQuad *, const decQuad *, const decQuad *, decContext *);
109
+ extern decQuad * decQuadDivideInteger(decQuad *, const decQuad *, const decQuad *, decContext *);
110
+ extern decQuad * decQuadFMA(decQuad *, const decQuad *, const decQuad *, const decQuad *, decContext *);
111
+ extern decQuad * decQuadInvert(decQuad *, const decQuad *, decContext *);
112
+ extern decQuad * decQuadLogB(decQuad *, const decQuad *, decContext *);
113
+ extern decQuad * decQuadMax(decQuad *, const decQuad *, const decQuad *, decContext *);
114
+ extern decQuad * decQuadMaxMag(decQuad *, const decQuad *, const decQuad *, decContext *);
115
+ extern decQuad * decQuadMin(decQuad *, const decQuad *, const decQuad *, decContext *);
116
+ extern decQuad * decQuadMinMag(decQuad *, const decQuad *, const decQuad *, decContext *);
117
+ extern decQuad * decQuadMinus(decQuad *, const decQuad *, decContext *);
118
+ extern decQuad * decQuadMultiply(decQuad *, const decQuad *, const decQuad *, decContext *);
119
+ extern decQuad * decQuadNextMinus(decQuad *, const decQuad *, decContext *);
120
+ extern decQuad * decQuadNextPlus(decQuad *, const decQuad *, decContext *);
121
+ extern decQuad * decQuadNextToward(decQuad *, const decQuad *, const decQuad *, decContext *);
122
+ extern decQuad * decQuadOr(decQuad *, const decQuad *, const decQuad *, decContext *);
123
+ extern decQuad * decQuadPlus(decQuad *, const decQuad *, decContext *);
124
+ extern decQuad * decQuadQuantize(decQuad *, const decQuad *, const decQuad *, decContext *);
125
+ extern decQuad * decQuadReduce(decQuad *, const decQuad *, decContext *);
126
+ extern decQuad * decQuadRemainder(decQuad *, const decQuad *, const decQuad *, decContext *);
127
+ extern decQuad * decQuadRemainderNear(decQuad *, const decQuad *, const decQuad *, decContext *);
128
+ extern decQuad * decQuadRotate(decQuad *, const decQuad *, const decQuad *, decContext *);
129
+ extern decQuad * decQuadScaleB(decQuad *, const decQuad *, const decQuad *, decContext *);
130
+ extern decQuad * decQuadShift(decQuad *, const decQuad *, const decQuad *, decContext *);
131
+ extern decQuad * decQuadSubtract(decQuad *, const decQuad *, const decQuad *, decContext *);
132
+ extern decQuad * decQuadToIntegralValue(decQuad *, const decQuad *, decContext *, enum rounding);
133
+ extern decQuad * decQuadToIntegralExact(decQuad *, const decQuad *, decContext *);
134
+ extern decQuad * decQuadXor(decQuad *, const decQuad *, const decQuad *, decContext *);
135
+
136
+ /* Comparisons */
137
+ extern decQuad * decQuadCompare(decQuad *, const decQuad *, const decQuad *, decContext *);
138
+ extern decQuad * decQuadCompareSignal(decQuad *, const decQuad *, const decQuad *, decContext *);
139
+ extern decQuad * decQuadCompareTotal(decQuad *, const decQuad *, const decQuad *);
140
+ extern decQuad * decQuadCompareTotalMag(decQuad *, const decQuad *, const decQuad *);
141
+
142
+ /* Copies */
143
+ extern decQuad * decQuadCanonical(decQuad *, const decQuad *);
144
+ extern decQuad * decQuadCopy(decQuad *, const decQuad *);
145
+ extern decQuad * decQuadCopyAbs(decQuad *, const decQuad *);
146
+ extern decQuad * decQuadCopyNegate(decQuad *, const decQuad *);
147
+ extern decQuad * decQuadCopySign(decQuad *, const decQuad *, const decQuad *);
148
+
149
+ /* Non-computational */
150
+ extern enum decClass decQuadClass(const decQuad *);
151
+ extern const char * decQuadClassString(const decQuad *);
152
+ extern uint32_t decQuadDigits(const decQuad *);
153
+ extern uint32_t decQuadIsCanonical(const decQuad *);
154
+ extern uint32_t decQuadIsFinite(const decQuad *);
155
+ extern uint32_t decQuadIsInteger(const decQuad *);
156
+ extern uint32_t decQuadIsLogical(const decQuad *);
157
+ extern uint32_t decQuadIsInfinite(const decQuad *);
158
+ extern uint32_t decQuadIsNaN(const decQuad *);
159
+ extern uint32_t decQuadIsNegative(const decQuad *);
160
+ extern uint32_t decQuadIsNormal(const decQuad *);
161
+ extern uint32_t decQuadIsPositive(const decQuad *);
162
+ extern uint32_t decQuadIsSignaling(const decQuad *);
163
+ extern uint32_t decQuadIsSignalling(const decQuad *);
164
+ extern uint32_t decQuadIsSigned(const decQuad *);
165
+ extern uint32_t decQuadIsSubnormal(const decQuad *);
166
+ extern uint32_t decQuadIsZero(const decQuad *);
167
+ extern uint32_t decQuadRadix(const decQuad *);
168
+ extern uint32_t decQuadSameQuantum(const decQuad *, const decQuad *);
169
+ extern const char * decQuadVersion(void);
170
+
171
+ /* decNumber conversions; these are implemented as macros so as not */
172
+ /* to force a dependency on decimal128 and decNumber in decQuad. */
173
+ /* decQuadFromNumber returns a decimal128 * to avoid warnings. */
174
+ #define decQuadToNumber(dq, dn) decimal128ToNumber((decimal128 *)(dq), dn)
175
+ #define decQuadFromNumber(dq, dn, set) decimal128FromNumber((decimal128 *)(dq), dn, set)
176
+
177
+ #endif
@@ -0,0 +1,71 @@
1
+ /* ------------------------------------------------------------------ */
2
+ /* decSingle.c -- decSingle operations module */
3
+ /* ------------------------------------------------------------------ */
4
+ /* Copyright (c) IBM Corporation, 2000, 2008. 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 included in the package as decNumber.pdf. This */
11
+ /* document is also available in HTML, together with 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
+ /* This module comprises decSingle operations (including conversions) */
20
+ /* ------------------------------------------------------------------ */
21
+
22
+ #include "decContext.h" // public includes
23
+ #include "decSingle.h" // public includes
24
+
25
+ /* Constant mappings for shared code */
26
+ #define DECPMAX DECSINGLE_Pmax
27
+ #define DECEMIN DECSINGLE_Emin
28
+ #define DECEMAX DECSINGLE_Emax
29
+ #define DECEMAXD DECSINGLE_EmaxD
30
+ #define DECBYTES DECSINGLE_Bytes
31
+ #define DECSTRING DECSINGLE_String
32
+ #define DECECONL DECSINGLE_EconL
33
+ #define DECBIAS DECSINGLE_Bias
34
+ #define DECLETS DECSINGLE_Declets
35
+ #define DECQTINY (-DECSINGLE_Bias)
36
+ // parameters of next-wider format
37
+ #define DECWBYTES DECDOUBLE_Bytes
38
+ #define DECWPMAX DECDOUBLE_Pmax
39
+ #define DECWECONL DECDOUBLE_EconL
40
+ #define DECWBIAS DECDOUBLE_Bias
41
+
42
+ /* Type and function mappings for shared code */
43
+ #define decFloat decSingle // Type name
44
+ #define decFloatWider decDouble // Type name
45
+
46
+ // Utility (binary results, extractors, etc.)
47
+ #define decFloatFromBCD decSingleFromBCD
48
+ #define decFloatFromPacked decSingleFromPacked
49
+ #define decFloatFromPackedChecked decSingleFromPackedChecked
50
+ #define decFloatFromString decSingleFromString
51
+ #define decFloatFromWider decSingleFromWider
52
+ #define decFloatGetCoefficient decSingleGetCoefficient
53
+ #define decFloatGetExponent decSingleGetExponent
54
+ #define decFloatSetCoefficient decSingleSetCoefficient
55
+ #define decFloatSetExponent decSingleSetExponent
56
+ #define decFloatShow decSingleShow
57
+ #define decFloatToBCD decSingleToBCD
58
+ #define decFloatToEngString decSingleToEngString
59
+ #define decFloatToPacked decSingleToPacked
60
+ #define decFloatToString decSingleToString
61
+ #define decFloatToWider decSingleToWider
62
+ #define decFloatZero decSingleZero
63
+
64
+ // Non-computational
65
+ #define decFloatRadix decSingleRadix
66
+ #define decFloatVersion decSingleVersion
67
+
68
+ #include "decNumberLocal.h" // local includes (need DECPMAX)
69
+ #include "decCommon.c" // non-basic decFloat routines
70
+ // [Do not include decBasic.c for decimal32]
71
+