Add decNumber library
The library adds support for decimal numbers of arbitrary length. Downloaded from ICU, under ICU 1.8.1 license http://download.icu-project.org/files/decNumber/decNumber-icu-368.zip
This commit is contained in:
1 parent
37b2d2129e
commit
b6be13d5de
36 files changed
+20503
No files matched your search
@@ -0,0 +1,38 @@
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Decimal Number Library Demonstration program */
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Copyright (c) IBM Corporation, 2001, 2007. All rights reserved. */
|
||||
/* ----------------------------------------------------------------+- */
|
||||
/* right margin -->| */
|
||||
|
||||
// example1.c -- convert the first two argument words to decNumber,
|
||||
// add them together, and display the result
|
||||
|
||||
#define DECNUMDIGITS 34 // work with up to 34 digits
|
||||
#include "decNumber.h" // base number library
|
||||
#include <stdio.h> // for printf
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
decNumber a, b; // working numbers
|
||||
decContext set; // working context
|
||||
char string[DECNUMDIGITS+14]; // conversion buffer
|
||||
|
||||
decContextTestEndian(0); // warn if DECLITEND is wrong
|
||||
|
||||
if (argc<3) { // not enough words
|
||||
printf("Please supply two numbers to add.\n");
|
||||
return 1;
|
||||
}
|
||||
decContextDefault(&set, DEC_INIT_BASE); // initialize
|
||||
set.traps=0; // no traps, thank you
|
||||
set.digits=DECNUMDIGITS; // set precision
|
||||
|
||||
decNumberFromString(&a, argv[1], &set);
|
||||
decNumberFromString(&b, argv[2], &set);
|
||||
|
||||
decNumberAdd(&a, &a, &b, &set); // a=a+b
|
||||
decNumberToString(&a, string);
|
||||
|
||||
printf("%s + %s => %s\n", argv[1], argv[2], string);
|
||||
return 0;
|
||||
} // main
|
||||
Reference in new issue
Block a user