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