summaryrefslogtreecommitdiff
path: root/src/operations/multiplication/testMultiplication.c
blob: 38c43438f916c8be9cc378cfa1a5936b449ca567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 *  Copyright (C) 2006-2008 - INRIA - Bruno JOFRET
 *
 *  This file must be used under the terms of the CeCILL.
 *  This source file is licensed as described in the file COPYING, which
 *  you should have received as part of this distribution.  The terms
 *  are also available at
 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "multiplication.h"

#define SIZE 10000000
/*
#define LOCAL_DEBUG 
*/
static void ztimessTest(void) {
  doubleComplex M1;
  doubleComplex M2;
  doubleComplex M1_by_M2;

  int i = 0;

  srand(1);
  for (i = 0; i < SIZE; ++i) {
    M1 = DoubleComplex((double) rand(), (double) rand());
    M2 = DoubleComplex((double) rand(), (double) rand());

    M1_by_M2 = ztimess(M1, M2);
#ifdef LOCAL_DEBUG
    /*ATTENTION à modifier (c'est du copier coller de testDivision)
    printf("erreurR = %e\n", fabs(zreals(M1_by_M2) - zreals(num)/zreals(den) )/fabs(zreals(M1_by_M2)));
    printf("erreurI = %e\n", fabs(zimags(M1_by_M2) - zimags(num)/zreals(den) )/fabs(zimags(M1_by_M2)));*/
#endif
    if (zreals(M1_by_M2)<1e-14 && (zreals(M1)*zreals(M2) - zimags(M1)*zimags(M2)) < 1e-18 ) 
	assert(1);
   else 
	assert( fabs(zreals(M1_by_M2) - (zreals(M1)*zreals(M2) - zimags(M1)*zimags(M2)) )/fabs(zreals(M1_by_M2)) <= 1e-16);

   if (  zimags(M1_by_M2) < 1e-14 && (zreals(M1)*zimags(M2) + zimags(M1)*zreals(M2)) < 1e-18 )
        assert ( 1 ) ;
   else
	assert( fabs(zimags(M1_by_M2) - (zreals(M1)*zimags(M2) + zimags(M1)*zreals(M2)) )/fabs(zimags(M1_by_M2)) <= 1e-16);
  }
}

static void ctimessTest(void) {
  floatComplex M1;
  floatComplex M2;
  floatComplex M1_by_M2;

  int i = 0;

  srand(1);
  for (i = 0; i < SIZE; ++i) {
    M1 = FloatComplex((float) rand(), (float) rand());
    M2 = FloatComplex((float) rand(), (float) rand());

    M1_by_M2 = ctimess(M1, M2);
#ifdef LOCAL_DEBUG
    /*ATTENTION à modifier (c'est du copier coller de testDivision)
    printf("erreurR = %e\n", creals(M1_by_M2) - (creals(num)/creals(den))/creals(M1_by_M2));
    printf("erreurI = %e\n", cimags(M1_by_M2) - (cimags(num)/creals(den))/cimags(M1_by_M2));*/
#endif
  if (creals(M1_by_M2)<1e-14 && (creals(M1)*creals(M2) - cimags(M1)*cimags(M2)) < 1e-18 ) 
	assert(1);
  else 
	assert( fabs(creals(M1_by_M2) - (creals(M1)*creals(M2) - cimags(M1)*cimags(M2)) )/fabs(creals(M1_by_M2)) < 1e-7);

  if (  cimags(M1_by_M2) < 1e-14 && (creals(M1)*cimags(M2) + cimags(M1)*creals(M2)) < 1e-18 )
        assert ( 1 ) ;
  else
    assert( fabs(cimags(M1_by_M2) - (creals(M1)*cimags(M2) + cimags(M1)*creals(M2)) )/fabs(cimags(M1_by_M2)) < 1e-7);
  }
}


static int testMult(void) {

  ztimessTest();
  ctimessTest();
  return 0;
}



int main(void) {
  assert(testMult() == 0);
  return 0;
}