VectorAdd2d and VectorAdd3d
in genMath.lib

Vector Functions            Function List by Category            Alphabetical Functions

Sample Code

int VectorAdd2d(
                             float *VectorA,       // pointer to array holding vector A
                             float *VectorB,       // pointer to array holding vector B
                             float *Sum)             // pointer to store result

int VectorAdd3d(
                             float *VectorA,       // pointer to array holding vector A
                             float *VectorB,       // pointer to array holding vector B
                             float *Sum)             // pointer to store result

These functions add two 2-d or 3-d vectors:

2-d Vector Sum(0)  = a(0) + b(0)
2-d Vector Sum(1)  = a(1) + b(1)

3-d Vector Sum(0)  = a(0) + b(0)
3-d Vector Sum(1)  = a(1) + b(1)
3-d Vector Sum(2)  = a(2) + b(2)

Calls to these routines will be faster than calls to genVectorAdd, for two reasons.
First, the dimension does not have to be passed as a parameter, and second, the loops
in these routines are unrolled.

Note that by using multiple calls, these routines can be used to add larger dimension
vectors, if care is taken in the passing of the pointers.

 

The return code is errno, defined in the C standard library (math.h).  This is an integer value
for math errors.

 
Sample Application:
/////////// splVAdd.c for VectorAdd3d Library Function ///////////////
//								    //																//
//	For this sample, 3-d vectors are used.  Vectors are stored  //
//	in arrays a and b, and the sum is returned into	    	    //
//	the array c.						    //
//								    //
//	Use of VectorAdd2d is similar.				    //
//								    //
//////////////////////////////////////////////////////////////////////

//////////////////////////// INCLUDES ////////////////////////////////

#include "stdio.h"
#include "genMath.h"

////////////////////////////// MAIN //////////////////////////////////
void main()
{

	//local declarations
	//integers
	int i;			// dimension counter
	int retcode;		// return code for call to VectorAdd3d

	//floats
	float a[3];		// vector A
	float b[3];		// vector B
	float c[3];		// resultant vector, C

	//character strings
	char  ch;		//input string to exit

	//intialize the A and B vectors
	a[0] = (float)1.234;
	a[1] = (float)-.678;
	a[2] = (float)10.3;

	b[0] = (float)4.559;
	b[1] = (float)3.24;
	b[2] = (float)0.3422;

	//compute the vector sum
	retcode = VectorAdd3d(a,b,c);
	
	//display the result
	
	printf("%s", "Resultant Components: \n\n");

	for(i=0;i<=2;++i){
	
		printf("%s%d%s%f%s", "c[",i,"] = ", c[i],"\n");
	
	}

	printf("%s","\n");

	//display closing message and wait for <enter> before exiting
	printf("Press <Enter> to end");
	scanf("%c", &ch);

} // End Main

/////////////////////////////// End splVAdd.c ///////////////////////