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.
- data/README +20 -0
- data/dec_number.gemspec +13 -0
- data/ext/dec_number/Gemfile +4 -0
- data/ext/dec_number/NOTES +10 -0
- data/ext/dec_number/decNumber/ICU-license.html +45 -0
- data/ext/dec_number/decNumber/Makefile.am +3 -0
- data/ext/dec_number/decNumber/Makefile.in +680 -0
- data/ext/dec_number/decNumber/aclocal.m4 +8988 -0
- data/ext/dec_number/decNumber/autom4te.cache/output.0 +5107 -0
- data/ext/dec_number/decNumber/autom4te.cache/output.1 +6026 -0
- data/ext/dec_number/decNumber/autom4te.cache/output.2 +13468 -0
- data/ext/dec_number/decNumber/autom4te.cache/output.3 +13472 -0
- data/ext/dec_number/decNumber/autom4te.cache/requests +407 -0
- data/ext/dec_number/decNumber/autom4te.cache/traces.0 +352 -0
- data/ext/dec_number/decNumber/autom4te.cache/traces.1 +772 -0
- data/ext/dec_number/decNumber/autom4te.cache/traces.2 +591 -0
- data/ext/dec_number/decNumber/autom4te.cache/traces.3 +2362 -0
- data/ext/dec_number/decNumber/config.guess +1501 -0
- data/ext/dec_number/decNumber/config.h.in +142 -0
- data/ext/dec_number/decNumber/config.sub +1705 -0
- data/ext/dec_number/decNumber/configure +13468 -0
- data/ext/dec_number/decNumber/configure.ac +36 -0
- data/ext/dec_number/decNumber/decBasic.c +3908 -0
- data/ext/dec_number/decNumber/decCommon.c +1835 -0
- data/ext/dec_number/decNumber/decContext.c +437 -0
- data/ext/dec_number/decNumber/decContext.h +254 -0
- data/ext/dec_number/decNumber/decDPD.h +1185 -0
- data/ext/dec_number/decNumber/decDouble.c +140 -0
- data/ext/dec_number/decNumber/decDouble.h +155 -0
- data/ext/dec_number/decNumber/decNumber.c +8141 -0
- data/ext/dec_number/decNumber/decNumber.h +182 -0
- data/ext/dec_number/decNumber/decNumberLocal.h +757 -0
- data/ext/dec_number/decNumber/decPacked.c +220 -0
- data/ext/dec_number/decNumber/decPacked.h +52 -0
- data/ext/dec_number/decNumber/decQuad.c +135 -0
- data/ext/dec_number/decNumber/decQuad.h +177 -0
- data/ext/dec_number/decNumber/decSingle.c +71 -0
- data/ext/dec_number/decNumber/decSingle.h +86 -0
- data/ext/dec_number/decNumber/decimal128.c +553 -0
- data/ext/dec_number/decNumber/decimal128.h +81 -0
- data/ext/dec_number/decNumber/decimal32.c +476 -0
- data/ext/dec_number/decNumber/decimal32.h +81 -0
- data/ext/dec_number/decNumber/decimal64.c +839 -0
- data/ext/dec_number/decNumber/decimal64.h +83 -0
- data/ext/dec_number/decNumber/decnumber.pdf +0 -0
- data/ext/dec_number/decNumber/depcomp +630 -0
- data/ext/dec_number/decNumber/example1.c +38 -0
- data/ext/dec_number/decNumber/example2.c +52 -0
- data/ext/dec_number/decNumber/example3.c +64 -0
- data/ext/dec_number/decNumber/example4.c +61 -0
- data/ext/dec_number/decNumber/example5.c +36 -0
- data/ext/dec_number/decNumber/example6.c +61 -0
- data/ext/dec_number/decNumber/example7.c +35 -0
- data/ext/dec_number/decNumber/example8.c +39 -0
- data/ext/dec_number/decNumber/install-sh +520 -0
- data/ext/dec_number/decNumber/libdecNumber.a +0 -0
- data/ext/dec_number/decNumber/ltmain.sh +8745 -0
- data/ext/dec_number/decNumber/missing +376 -0
- data/ext/dec_number/decNumber/readme.txt +81 -0
- data/ext/dec_number/dec_number.c +464 -0
- data/ext/dec_number/extconf.rb +52 -0
- data/ext/dec_number/extconf2.rb +50 -0
- data/ext/dec_number/recompile.sh +3 -0
- data/ext/dec_number/test_dec_number.rb +236 -0
- data/ext/dec_number/test_numeric.rb +235 -0
- metadata +111 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example2.c -- calculate compound interest
|
9
|
+
// Arguments are investment, rate (%), and years
|
10
|
+
|
11
|
+
#define DECNUMDIGITS 38 // work with up to 38 digits
|
12
|
+
#include "decNumber.h" // base number library
|
13
|
+
#include <stdio.h> // for printf
|
14
|
+
|
15
|
+
int main(int argc, char *argv[]) {
|
16
|
+
int need=3;
|
17
|
+
if (argc<need+1) { // not enough words
|
18
|
+
printf("Please supply %d number(s).\n", need);
|
19
|
+
return 1;
|
20
|
+
}
|
21
|
+
|
22
|
+
{ // excerpt for User's Guide starts here--------------------------|
|
23
|
+
decNumber one, mtwo, hundred; // constants
|
24
|
+
decNumber start, rate, years; // parameters
|
25
|
+
decNumber total; // result
|
26
|
+
decContext set; // working context
|
27
|
+
char string[DECNUMDIGITS+14]; // conversion buffer
|
28
|
+
|
29
|
+
decContextDefault(&set, DEC_INIT_BASE); // initialize
|
30
|
+
set.traps=0; // no traps
|
31
|
+
set.digits=25; // precision 25
|
32
|
+
decNumberFromString(&one, "1", &set); // set constants
|
33
|
+
decNumberFromString(&mtwo, "-2", &set);
|
34
|
+
decNumberFromString(&hundred, "100", &set);
|
35
|
+
|
36
|
+
decNumberFromString(&start, argv[1], &set); // parameter words
|
37
|
+
decNumberFromString(&rate, argv[2], &set);
|
38
|
+
decNumberFromString(&years, argv[3], &set);
|
39
|
+
|
40
|
+
decNumberDivide(&rate, &rate, &hundred, &set); // rate=rate/100
|
41
|
+
decNumberAdd(&rate, &rate, &one, &set); // rate=rate+1
|
42
|
+
decNumberPower(&rate, &rate, &years, &set); // rate=rate^years
|
43
|
+
decNumberMultiply(&total, &rate, &start, &set); // total=rate*start
|
44
|
+
decNumberRescale(&total, &total, &mtwo, &set); // two digits please
|
45
|
+
|
46
|
+
decNumberToString(&total, string);
|
47
|
+
printf("%s at %s%% for %s years => %s\n",
|
48
|
+
argv[1], argv[2], argv[3], string);
|
49
|
+
|
50
|
+
} //---------------------------------------------------------------|
|
51
|
+
return 0;
|
52
|
+
} // main
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example3.c -- calculate compound interest, passive checking
|
9
|
+
// Arguments are investment, rate (%), and years
|
10
|
+
|
11
|
+
#define DECNUMDIGITS 38 // work with up to 38 digits
|
12
|
+
#include "decNumber.h" // base number library
|
13
|
+
#include <stdio.h> // for printf
|
14
|
+
|
15
|
+
int main(int argc, char *argv[]) {
|
16
|
+
int need=3;
|
17
|
+
if (argc<need+1) { // not enough words
|
18
|
+
printf("Please supply %d number(s).\n", need);
|
19
|
+
return 1;
|
20
|
+
}
|
21
|
+
|
22
|
+
{ // start of Example 2 segment
|
23
|
+
decNumber one, mtwo, hundred; // constants
|
24
|
+
decNumber start, rate, years; // parameters
|
25
|
+
decNumber total; // result
|
26
|
+
decContext set; // working context
|
27
|
+
char string[DECNUMDIGITS+14]; // conversion buffer
|
28
|
+
|
29
|
+
decContextDefault(&set, DEC_INIT_BASE); // initialize
|
30
|
+
set.traps=0; // no traps
|
31
|
+
set.digits=25; // precision 25
|
32
|
+
decNumberFromString(&one, "1", &set); // set constants
|
33
|
+
decNumberFromString(&mtwo, "-2", &set);
|
34
|
+
decNumberFromString(&hundred, "100", &set);
|
35
|
+
|
36
|
+
// [snip...
|
37
|
+
decNumberFromString(&start, argv[1], &set); // parameter words
|
38
|
+
decNumberFromString(&rate, argv[2], &set);
|
39
|
+
decNumberFromString(&years, argv[3], &set);
|
40
|
+
if (set.status & DEC_Errors) {
|
41
|
+
printf("An input argument word was invalid [%s]\n",
|
42
|
+
decContextStatusToString(&set));
|
43
|
+
return 1;
|
44
|
+
}
|
45
|
+
decNumberDivide(&rate, &rate, &hundred, &set); // rate=rate/100
|
46
|
+
decNumberAdd(&rate, &rate, &one, &set); // rate=rate+1
|
47
|
+
decNumberPower(&rate, &rate, &years, &set); // rate=rate^years
|
48
|
+
decNumberMultiply(&total, &rate, &start, &set); // total=rate*start
|
49
|
+
decNumberRescale(&total, &total, &mtwo, &set); // two digits please
|
50
|
+
if (set.status & DEC_Errors) {
|
51
|
+
set.status &= DEC_Errors; // keep only errors
|
52
|
+
printf("Result could not be calculated [%s]\n",
|
53
|
+
decContextStatusToString(&set));
|
54
|
+
return 1;
|
55
|
+
}
|
56
|
+
// ...snip]
|
57
|
+
|
58
|
+
decNumberToString(&total, string);
|
59
|
+
printf("%s at %s%% for %s years => %s\n",
|
60
|
+
argv[1], argv[2], argv[3], string);
|
61
|
+
|
62
|
+
} //---------------------------------------------------------------|
|
63
|
+
return 0;
|
64
|
+
} // main
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example4.c -- add two numbers, active error handling
|
9
|
+
// Arguments are two numbers
|
10
|
+
|
11
|
+
#define DECNUMDIGITS 38 // work with up to 38 digits
|
12
|
+
#include "decNumber.h" // base number library
|
13
|
+
#include <stdio.h> // for printf
|
14
|
+
|
15
|
+
// [snip...
|
16
|
+
#include <signal.h> // signal handling
|
17
|
+
#include <setjmp.h> // setjmp/longjmp
|
18
|
+
|
19
|
+
jmp_buf preserve; // stack snapshot
|
20
|
+
|
21
|
+
void signalHandler(int); // prototype for GCC
|
22
|
+
void signalHandler(int sig) {
|
23
|
+
signal(SIGFPE, signalHandler); // re-enable
|
24
|
+
longjmp(preserve, sig); // branch to preserved point
|
25
|
+
}
|
26
|
+
// ...snip]
|
27
|
+
int main(int argc, char *argv[]) {
|
28
|
+
decNumber a, b; // working numbers
|
29
|
+
decContext set; // working context
|
30
|
+
char string[DECNUMDIGITS+14]; // conversion buffer
|
31
|
+
int value; // work variable
|
32
|
+
|
33
|
+
if (argc<3) { // not enough words
|
34
|
+
printf("Please supply two numbers to add.\n");
|
35
|
+
return 1;
|
36
|
+
}
|
37
|
+
decContextDefault(&set, DEC_INIT_BASE); // initialize
|
38
|
+
|
39
|
+
// [snip...
|
40
|
+
signal(SIGFPE, signalHandler); // set up signal handler
|
41
|
+
value=setjmp(preserve); // preserve and test environment
|
42
|
+
if (value) { // (non-0 after longjmp)
|
43
|
+
set.status &= DEC_Errors; // keep only errors
|
44
|
+
printf("Signal trapped [%s].\n", decContextStatusToString(&set));
|
45
|
+
return 1;
|
46
|
+
}
|
47
|
+
// ...snip]
|
48
|
+
|
49
|
+
// [change from Example 1, here]
|
50
|
+
// leave traps enabled
|
51
|
+
set.digits=DECNUMDIGITS; // set precision
|
52
|
+
|
53
|
+
decNumberFromString(&a, argv[1], &set);
|
54
|
+
decNumberFromString(&b, argv[2], &set);
|
55
|
+
|
56
|
+
decNumberAdd(&a, &a, &b, &set); // A=A+B
|
57
|
+
decNumberToString(&a, string);
|
58
|
+
|
59
|
+
printf("%s + %s => %s\n", argv[1], argv[2], string);
|
60
|
+
return 0;
|
61
|
+
} // main
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001, 2007. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example5.c -- decimal64 conversions
|
9
|
+
|
10
|
+
#include "decimal64.h" // decimal64 and decNumber library
|
11
|
+
#include <stdio.h> // for (s)printf
|
12
|
+
|
13
|
+
int main(int argc, char *argv[]) {
|
14
|
+
decimal64 a; // working decimal64 number
|
15
|
+
decNumber d; // working number
|
16
|
+
decContext set; // working context
|
17
|
+
char string[DECIMAL64_String]; // number->string buffer
|
18
|
+
char hexes[25]; // decimal64->hex buffer
|
19
|
+
int i; // counter
|
20
|
+
|
21
|
+
if (argc<2) { // not enough words
|
22
|
+
printf("Please supply a number.\n");
|
23
|
+
return 1;
|
24
|
+
}
|
25
|
+
decContextDefault(&set, DEC_INIT_DECIMAL64); // initialize
|
26
|
+
|
27
|
+
decimal64FromString(&a, argv[1], &set);
|
28
|
+
// lay out the decimal64 as eight hexadecimal pairs
|
29
|
+
for (i=0; i<8; i++) {
|
30
|
+
sprintf(&hexes[i*3], "%02x ", a.bytes[i]);
|
31
|
+
}
|
32
|
+
decimal64ToNumber(&a, &d);
|
33
|
+
decNumberToString(&d, string);
|
34
|
+
printf("%s => %s=> %s\n", argv[1], hexes, string);
|
35
|
+
return 0;
|
36
|
+
} // main
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example6.c -- calculate compound interest, using Packed Decimal
|
9
|
+
// Values are investment, rate (%), and years
|
10
|
+
|
11
|
+
#include "decPacked.h" // base number library
|
12
|
+
#include <stdio.h> // for printf
|
13
|
+
|
14
|
+
int main(int argc, char *argv[]) {
|
15
|
+
{ // excerpt for User's Guide starts here--------------------------|
|
16
|
+
decNumber one, mtwo, hundred; // constants
|
17
|
+
decNumber start, rate, years; // parameters
|
18
|
+
decNumber total; // result
|
19
|
+
decContext set; // working context
|
20
|
+
|
21
|
+
uint8_t startpack[]={0x01, 0x00, 0x00, 0x0C}; // investment=100000
|
22
|
+
int32_t startscale=0;
|
23
|
+
uint8_t ratepack[]={0x06, 0x5C}; // rate=6.5%
|
24
|
+
int32_t ratescale=1;
|
25
|
+
uint8_t yearspack[]={0x02, 0x0C}; // years=20
|
26
|
+
int32_t yearsscale=0;
|
27
|
+
uint8_t respack[16]; // result, packed
|
28
|
+
int32_t resscale; // ..
|
29
|
+
char hexes[49]; // for packed->hex
|
30
|
+
int i; // counter
|
31
|
+
|
32
|
+
if (argc<0) printf("%s", argv[1]); // noop for warning
|
33
|
+
|
34
|
+
decContextDefault(&set, DEC_INIT_BASE); // initialize
|
35
|
+
set.traps=0; // no traps
|
36
|
+
set.digits=25; // precision 25
|
37
|
+
decNumberFromString(&one, "1", &set); // set constants
|
38
|
+
decNumberFromString(&mtwo, "-2", &set);
|
39
|
+
decNumberFromString(&hundred, "100", &set);
|
40
|
+
|
41
|
+
decPackedToNumber(startpack, sizeof(startpack), &startscale, &start);
|
42
|
+
decPackedToNumber(ratepack, sizeof(ratepack), &ratescale, &rate);
|
43
|
+
decPackedToNumber(yearspack, sizeof(yearspack), &yearsscale, &years);
|
44
|
+
|
45
|
+
decNumberDivide(&rate, &rate, &hundred, &set); // rate=rate/100
|
46
|
+
decNumberAdd(&rate, &rate, &one, &set); // rate=rate+1
|
47
|
+
decNumberPower(&rate, &rate, &years, &set); // rate=rate^years
|
48
|
+
decNumberMultiply(&total, &rate, &start, &set); // total=rate*start
|
49
|
+
decNumberRescale(&total, &total, &mtwo, &set); // two digits please
|
50
|
+
|
51
|
+
decPackedFromNumber(respack, sizeof(respack), &resscale, &total);
|
52
|
+
|
53
|
+
// lay out the total as sixteen hexadecimal pairs
|
54
|
+
for (i=0; i<16; i++) {
|
55
|
+
sprintf(&hexes[i*3], "%02x ", respack[i]);
|
56
|
+
}
|
57
|
+
printf("Result: %s (scale=%ld)\n", hexes, (long int)resscale);
|
58
|
+
|
59
|
+
} //---------------------------------------------------------------|
|
60
|
+
return 0;
|
61
|
+
} // main
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001, 2008. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example7.c -- using decQuad to add two numbers together
|
9
|
+
|
10
|
+
// compile: example7.c decContext.c decQuad.c
|
11
|
+
|
12
|
+
#include "decQuad.h" // decQuad library
|
13
|
+
#include <stdio.h> // for printf
|
14
|
+
|
15
|
+
int main(int argc, char *argv[]) {
|
16
|
+
decQuad a, b; // working decQuads
|
17
|
+
decContext set; // working context
|
18
|
+
char string[DECQUAD_String]; // number->string buffer
|
19
|
+
|
20
|
+
decContextTestEndian(0); // warn if DECLITEND is wrong
|
21
|
+
|
22
|
+
if (argc<3) { // not enough words
|
23
|
+
printf("Please supply two numbers to add.\n");
|
24
|
+
return 1;
|
25
|
+
}
|
26
|
+
decContextDefault(&set, DEC_INIT_DECQUAD); // initialize
|
27
|
+
|
28
|
+
decQuadFromString(&a, argv[1], &set);
|
29
|
+
decQuadFromString(&b, argv[2], &set);
|
30
|
+
decQuadAdd(&a, &a, &b, &set); // a=a+b
|
31
|
+
decQuadToString(&a, string);
|
32
|
+
|
33
|
+
printf("%s + %s => %s\n", argv[1], argv[2], string);
|
34
|
+
return 0;
|
35
|
+
} // main
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/* ------------------------------------------------------------------ */
|
2
|
+
/* Decimal Number Library Demonstration program */
|
3
|
+
/* ------------------------------------------------------------------ */
|
4
|
+
/* Copyright (c) IBM Corporation, 2001, 2007. All rights reserved. */
|
5
|
+
/* ----------------------------------------------------------------+- */
|
6
|
+
/* right margin -->| */
|
7
|
+
|
8
|
+
// example8.c -- using decQuad with the decNumber module
|
9
|
+
|
10
|
+
// compile: example8.c decContext.c decQuad.c
|
11
|
+
// and: decNumber.c decimal128.c decimal64.c
|
12
|
+
|
13
|
+
#include "decQuad.h" // decQuad library
|
14
|
+
#include "decimal128.h" // interface to decNumber
|
15
|
+
#include <stdio.h> // for printf
|
16
|
+
|
17
|
+
int main(int argc, char *argv[]) {
|
18
|
+
decQuad a; // working decQuad
|
19
|
+
decNumber numa, numb; // working decNumbers
|
20
|
+
decContext set; // working context
|
21
|
+
char string[DECQUAD_String]; // number->string buffer
|
22
|
+
|
23
|
+
if (argc<3) { // not enough words
|
24
|
+
printf("Please supply two numbers for power(2*a, b).\n");
|
25
|
+
return 1;
|
26
|
+
}
|
27
|
+
decContextDefault(&set, DEC_INIT_DECQUAD); // initialize
|
28
|
+
|
29
|
+
decQuadFromString(&a, argv[1], &set); // get a
|
30
|
+
decQuadAdd(&a, &a, &a, &set); // double a
|
31
|
+
decQuadToNumber(&a, &numa); // convert to decNumber
|
32
|
+
decNumberFromString(&numb, argv[2], &set);
|
33
|
+
decNumberPower(&numa, &numa, &numb, &set); // numa=numa**numb
|
34
|
+
decQuadFromNumber(&a, &numa, &set); // back via a Quad
|
35
|
+
decQuadToString(&a, string); // ..
|
36
|
+
|
37
|
+
printf("power(2*%s, %s) => %s\n", argv[1], argv[2], string);
|
38
|
+
return 0;
|
39
|
+
} // main
|