# Thread: Dot Product (includes attachment)

1. I think you're way out of your league.

It's hard to say whether you don't understand the programming aspect, or understand the math aspect.

If you don't understand the math, then it's going to be hard explaining what each of those parameters are for.

Since conj is unused inside the function, there's no point in passing anything useful, so
Code:
```c_sdot ( 0,        // unused conjugate
3,        // int n,
0.0,      // float alpha,
array_a,  // const float* x,
1,        // int incx,
0.0,      // float beta,
array_b,  // const float* y,
1,        // int incy,
results   // float* r
);```
Now paste that into your main() function and try compiling it.

Then add a loop to print the results[] array, and then perhaps figure out whether the resutl is what you expect.

2. attached is the code that i have been working on. could you please look at the code that i have written that is supposed to pass the arrays to the function so that it can calculate the answer

3. Try this.
Code:
```int main(void)
{
float array_a[3] = {1.0F,0.0F,1.0F};
float array_b[3] = {3.0F,3.0F,3.0F};
float result;

c_sdot(blas_no_conj, 3, 1.0F, array_a, 1, 1.0F, array_b, 1, &result);

return 0;
}```

4. it gives me six errors

5. >it gives me six errors

And those might be...?
Code:
```#include <stdio.h>

enum blas_conj_type {
blas_conj    = 191,
blas_no_conj = 192 };

void c_sdot(enum blas_conj_type conj,
int n,
float alpha,
const float *x, int incx,
float beta,
const float *y, int incy,
float *r)
{
int i, ix = 0, iy = 0;
float *r_i = r;
const float *x_i = x;
const float *y_i = y;
float alpha_i = alpha;
float beta_i = beta;
float x_ii;
float y_ii;
float r_v;
float prod;
float sum;
float tmp1;
float tmp2;

if ( n <= 0 )
{
*r_i = 0.0;
return;
}
r_v = r_i[0];
sum = 0.0; /* sum = 0 */

if ( incx < 0 ) ix = (-n+1)*incx;
if ( incy < 0 ) iy = (-n+1)*incx;
for ( i = 0; i < n; ++i )
{
x_ii = x_i[ix];
y_ii = y_i[iy];
prod = x_ii * y_ii; /* prod = x[i]*y[i] */
sum = sum + prod; /* sum = sum+prod */
ix += incx;
iy += incy;
} /* endfor */
tmp1 = sum * alpha_i; /* tmp1 = sum*alpha */
tmp2 = r_v * beta_i; /* tmp2 = r*beta */
tmp1 = tmp1 + tmp2; /* tmp1 = tmp1+tmp2 */
*r = tmp1; /* r = tmp1 */
} /* end c_sdot */

int main(void)
{
float array_a[3] = {1.0F,0.0F,1.0F};
float array_b[3] = {3.0F,3.0F,3.0F};
float result;

c_sdot(blas_no_conj, 3, 1.0F, array_a, 1, 1.0F, array_b, 1, &result);

return 0;
}

/* my output
*/```

6. Thank you so much for your help! My program works now, thanks to you. Just for my own clarification what does this mean:

1. enum blas_conj_type
blas_conj = 191,
blas_no_conj = 192

2. Also when you declared the array why did you put an F behind them

If I have any more questions I will be sure to ask you. You are very smart!

7. Just for my own clarification what does this mean:

1. enum blas_conj_type
blas_conj = 191,
blas_no_conj = 192
I don't have the header file cblas.h that you are #include-ing. So I did a quick search and found a definition here.
2. Also when you declared the array why did you put an F behind them
My preference. Floating-point constants without F suffixes are doubles by default. With the F suffixes, they are floats.

8. Thanks again for your help. If I need to reach you again. How do I do so

9. My preference. Floating-point constants without F suffixes are doubles by default. With the F suffixes, they are floats.

But no matter what all floats are converted to doubles by the compiler. Doubles are qwords and the native data type of the FPU. There is no speed hit/gain from using doubles/singles as it takes just as many clock cycles for the FPU to load a float as it does a double and vice versa.

Thanks to Fordy and others at flashdaddee for this information.