"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "gnussl-0.2.1/tests/c_gj_test.c" of archive gnussl-0.2.1.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /* Tests the compiled C-library, libgnussl.h.  Since all the functions in
    2 the library are simply fronts for the C++ functions, only one function is
    3 tested. */
    4 
    5 /*
    6 Copyright (C) 1996 Free Software Foundation
    7     written by R.D. Pierce (pierce@math.psu.edu)
    8 
    9 This software is free; you can redistribute it and/or modify it under the
   10 terms of the GNU General Public License as published by the Free
   11 Software Foundation; either version 2 of the License, or (at your
   12 option) any later version.  This software is distributed in the hope
   13 that it will be useful, but WITHOUT ANY WARRANTY; without even the
   14 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
   15 PURPOSE.  See the GNU General Public License for more details.
   16 You should have received a copy of the GNU General Public
   17 License along with this library; if not, write to the Free Software
   18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
   19 */
   20 
   21 #include<stdio.h>
   22 #include<stdlib.h>
   23 #include<c_gnussl.h>
   24 
   25 int main() {
   26   int dim=5,r,c;
   27   struct c_complex_matrix a,i;
   28   struct c_complex_matrix b,d;
   29   struct c_complex p1[dim*dim],p2[dim*dim],p3[dim*dim],p4[dim*dim];
   30   double maxr;
   31   for(r=0;r<dim*dim;r++) { p1[r].re=0.0; p1[r].im=0.0; }
   32   for(r=0;r<dim*dim;r++) { p2[r].re=0.0; p2[r].im=0.0; }
   33   for(r=0;r<dim*dim;r++) { p3[r].re=0.0; p3[r].im=0.0; }
   34   for(r=0;r<dim*dim;r++) { p4[r].re=0.0; p4[r].im=0.0; }
   35 
   36   maxr=(double)0x0fffffff;
   37   a.r_=a.c_=dim;
   38   a.data_=p1;
   39   b.r_=b.c_=dim;
   40   b.data_=p2;
   41   d.r_=d.c_=dim;
   42   d.data_=p3;
   43   i.r_=i.c_=dim;
   44   i.data_=p4;
   45 
   46   srand(1);
   47   for(r=1;r<=dim;r++) {
   48     for(c=1;c<=dim;c++) {
   49       a.data_[(r-1)*a.c_+c-1].re=rand()/maxr;
   50       a.data_[(r-1)*a.c_+c-1].im=rand()/maxr;
   51       b.data_[(r-1)*a.c_+c-1].re=a.data_[(r-1)*a.c_+c-1].re;
   52       b.data_[(r-1)*a.c_+c-1].im=a.data_[(r-1)*a.c_+c-1].im;
   53       i.data_[(r-1)*a.c_+c-1].re=0.0;
   54       i.data_[(r-1)*a.c_+c-1].im=0.0;
   55       d.data_[(r-1)*a.c_+c-1].re=0.0;
   56       d.data_[(r-1)*a.c_+c-1].im=0.0;
   57     }
   58     i.data_[(r-1)*a.c_+r-1].re=1.0;
   59     d.data_[(r-1)*a.c_+r-1].re=1.0;
   60   }
   61   complex_gauss_jordan(b,d,0.0,1,1,1);
   62   printf("\n\nCheck the deviation from the identity\n");
   63   for(r=1;r<=dim;r++) {
   64     for(c=1;c<=dim;c++)
   65       printf("(%e,%e)\t",i.data_[(r-1)*a.c_+c-1].re-b.data_[(r-1)*a.c_+c-1].re,
   66 i.data_[(r-1)*a.c_+c-1].im-b.data_[(r-1)*a.c_+c-1].im);
   67     printf("\n");
   68   }
   69   printf("\n\nCheck the deviation from the inverse\n");
   70   complex_mdotm(d,a,b);
   71   for(r=1;r<=dim;r++) {
   72     for(c=1;c<=dim;c++)
   73       printf("(%e,%e)\t",i.data_[(r-1)*a.c_+c-1].re-b.data_[(r-1)*a.c_+c-1].re,
   74 i.data_[(r-1)*a.c_+c-1].im-b.data_[(r-1)*a.c_+c-1].im);
   75     printf("\n");
   76     printf("\n");
   77   }
   78   return 0;
   79 }