"Fossies" - the Fresh Open Source Software Archive

Member "ccmath-2.2.1/xarm/test/txaop1.c" (12 Dec 2000, 2779 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 /*  txaop1.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:  xadd  xmul  xdiv
   10 
   11     Uses:  atox  prxpr  xtodub
   12 
   13     Input file:  data/aop1.dat
   14 */
   15 #define XMATH 1
   16 #include "ccmath.h"
   17 int decd=30;
   18 void main(int na,char **av)
   19 { struct xpr s,t,f;
   20   char nbx[64],nby[64];
   21   FILE *fp;
   22   if(na!=2){ printf("para: input_file\n"); exit(-1);}
   23   fp=fopen(*++av,"r");
   24   printf("     Test of Elementary Operations\n");
   25   while(fscanf(fp,"%s %s",nbx,nby)!=EOF){
   26     s=atox(nbx); t=atox(nby);
   27     printf(" x= "); prxpr(s,decd);
   28     printf(" y= "); prxpr(t,decd);
   29 
   30 /* extended precision addition */
   31     printf("add\n");
   32     f=xadd(s,t,0);
   33     printf(" %16.10f\n",xtodub(f)); prxpr(f,decd);
   34 
   35 /* extended precision subtraction */
   36     printf("subtract\n");
   37     f=xadd(s,t,1);
   38     printf(" %16.10f\n",xtodub(f)); prxpr(f,decd);
   39 
   40 /* extended precision multiplication */
   41     printf("multiply\n");
   42     f=xmul(s,t);
   43     printf(" %16.10f\n",xtodub(f)); prxpr(f,decd);
   44 
   45 /* extended precision division */
   46     printf("divide\n");
   47     f=xdiv(s,t);
   48     printf(" %16.10f\n",xtodub(f)); prxpr(f,decd);
   49    }
   50 }
   51 /*  Test output
   52 
   53      Test of Elementary Operations
   54  x=   1.000000000000000000000000000000e+0
   55  y=   4.000000000000000000000000000000e+0
   56 add
   57      5.0000000000
   58   5.000000000000000000000000000000e+0
   59 subtract
   60     -3.0000000000
   61  -3.000000000000000000000000000000e+0
   62 multiply
   63      4.0000000000
   64   4.000000000000000000000000000000e+0
   65 divide
   66      0.2500000000
   67   2.500000000000000000000000000000e-1
   68  x=  -2.300000000000000000000000000000e+0
   69  y=   3.147159000000000000000000000000e+0
   70 add
   71      0.8471590000
   72   8.471590000000000000000000000000e-1
   73 subtract
   74     -5.4471590000
   75  -5.447159000000000000000000000000e+0
   76 multiply
   77     -7.2384657000
   78  -7.238465700000000000000000000000e+0
   79 divide
   80     -0.7308178583
   81  -7.308178582651845680501048723627e-1
   82  x=   2.750000000000000000000000000000e+1
   83  y=  -3.360000000000000000000000000000e+1
   84 add
   85     -6.1000000000
   86  -6.100000000000000000000000000000e+0
   87 subtract
   88     61.1000000000
   89   6.110000000000000000000000000000e+1
   90 multiply
   91   -924.0000000000
   92  -9.240000000000000000000000000000e+2
   93 divide
   94     -0.8184523810
   95  -8.184523809523809523809523809524e-1
   96  x=  -1.110000000000000000000000000000e+1
   97  y=  -4.000000000000000000000000000000e-1
   98 add
   99    -11.5000000000
  100  -1.150000000000000000000000000000e+1
  101 subtract
  102    -10.7000000000
  103  -1.070000000000000000000000000000e+1
  104 multiply
  105      4.4400000000
  106   4.440000000000000000000000000000e+0
  107 divide
  108     27.7500000000
  109   2.775000000000000000000000000000e+1
  110 */