Skip to content
Myr

example8.c

This file

Path

vendor/decNumber/example8.c

39 lines · 1.7 KiB · C

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than fa6a2ff point at it.

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1–39why, one step back
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 17int 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