"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/complex/test/tcarith.c" (30 Oct 2000, 1562 Bytes) of package /linux/misc/old/ccmath-2.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*  tcarith.c    CCMATH mathematics library source code.
    2  *
    3  *  Copyright (C)  2000   Daniel A. Atkinson    All rights reserved.
    4  *  This code may be redistributed under the terms of the GNU library
    5  *  public license (LGPL). ( See the lgpl.license file for details.)
    6  * ------------------------------------------------------------------------
    7  */
    8 /*
    9     Test:  cadd  csub  cmul  cdiv
   10 
   11     interactive input with 'tcarith'
   12     input from file with 'tcarith data/carith.dat'
   13 */
   14 #include "ccmath.h"
   15 void main(int na,char **av)
   16 { Cpx a,b,f; FILE *fp;
   17   if(na>1) fp=fopen(*++av,"r");
   18   while(1){
   19     if(na==1){ printf(" a? b?\n");
   20       if(scanf("%lf %lf %lf %lf",&a.re,&a.im,&b.re,&b.im)==EOF) break;
   21      }
   22     else if(fscanf(fp,"%lf %lf %lf %lf",&a.re,&a.im,&b.re,&b.im) ==EOF) break;
   23     printf("   a=(%f, %f) b=(%f, %f)\n",a.re,a.im,b.re,b.im);
   24     f=cadd(a,b); printf(" a+b=(%f, %f)\n",f.re,f.im);
   25     f=csub(a,b); printf(" a-b=(%f, %f)\n",f.re,f.im);
   26     f=cmul(a,b); printf(" a*b=(%f, %f)\n",f.re,f.im);
   27     f=cdiv(a,b); printf(" a/b=(%f, %f)\n",f.re,f.im);
   28    }
   29 }
   30 /* Test output
   31 
   32    a=(1.000000, 1.000000) b=(2.000000, -0.500000)
   33  a+b=(3.000000, 0.500000)
   34  a-b=(-1.000000, 1.500000)
   35  a*b=(2.500000, 1.500000)
   36  a/b=(0.352941, 0.588235)
   37    a=(1.000000, 3.000000) b=(-3.000000, -1.600000)
   38  a+b=(-2.000000, 1.400000)
   39  a-b=(4.000000, 4.600000)
   40  a*b=(1.800000, -10.600000)
   41  a/b=(-0.674740, -0.640138)
   42    a=(0.200000, -1.000000) b=(-0.700000, 4.000000)
   43  a+b=(-0.500000, 3.000000)
   44  a-b=(0.900000, -5.000000)
   45  a*b=(3.860000, 1.500000)
   46  a/b=(-0.251061, -0.006064)
   47 */