github.com/matrixorigin/matrixone@v0.7.0/cgo/external/decNumber/example7.c (about) 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