GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-37a74d03c4
mult.c
Go to the documentation of this file.
1 /* Author: Bill Hoff,2-114C,8645,3563478 (hoff) at uicsl */
2 
3 /*!
4  * \fn int G_math_complex_mult (double *v1[2], int size1, double *v2[2], int
5  * size2, double *v3[2], int size3)
6  *
7  * \brief Multiply two complex vectors, point by point
8  *
9  * Vectors are in the form: real, imaginary (each a floating number).
10  * A vector can be of any size. Computes <b>v3</b> = <b>v1</b> *
11  * <b>v2</b>. <b>v3</b> should as big as the biggest of <b>v1</b> and
12  * <b>v2</b>.
13  *
14  * \param v1
15  * \param size1
16  * \param v2
17  * \param size2
18  * \param v3
19  * \param size3
20  * \return int
21  */
22 
23 int G_math_complex_mult(double *v1[2], int size1, double *v2[2], int size2,
24  double *v3[2], int size3)
25 {
26  int i, n;
27 
28  n = (size1 < size2 ? size1 : size2); /* get the smaller size */
29  for (i = 0; i < n; i++) {
30  *(v3[0] + i) =
31  *(v1[0] + i) * *(v2[0] + i) - *(v1[1] + i) * *(v2[1] + i);
32  *(v3[1] + i) =
33  *(v1[0] + i) * *(v2[1] + i) + *(v2[0] + i) * *(v1[1] + i);
34  }
35 
36  /* if unequal size, zero out remaining elements of larger vector */
37  if (size1 != size2)
38  for (i = n; i < size3; i++) {
39  *(v3[0] + i) = 0.0;
40  *(v3[1] + i) = 0.0;
41  }
42 
43  return 0;
44 }
int G_math_complex_mult(double *v1[2], int size1, double *v2[2], int size2, double *v3[2], int size3)
Definition: mult.c:23