VectorNegate2d and VectorNegate3d
in genMath.lib
Vector Functions Function List by Category Alphabetical Function
int VectorNegate2d(
float
*VectorA, // pointer to array holding
vector A
float
*VectorB, // pointer to array for
vector B
int VectorNegate3d(
float
*VectorA, // pointer to array holding
vector A
float *VectorB, // pointer to array for
vector B
These functions compute the negative of a 2-d and 3-d vectors:
b(i) = -a(i)
Calls
to these routines will be faster than calls to genVectorNegate,
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
negate 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:
///////////// splVNg3.c for VectorNegate3d Library Function ////////// // // // For this sample, 3-d vectors are used. The vector is // // stored in array a and the negative is returned in array b. // // // // The use of VectorNegate2d 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 VectorNegate3d //floats float a[3]; // vector float b[3]; // negative of vector //character strings char ch; //input string to exit //intialize the A vectors a[0] = (float)1.234; a[1] = (float)-.678; a[2] = (float)10.3; //negate the vector retcode = VectorNegate3d(a,b,3); //display the result printf("%s", "Resultant Components: \n\n"); for(i=0;i<=2;++i){ printf("%s%d%s%f%s", "b[",i,"] = ", b[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 splVNg3.c ///////////////////////
The reader may verify that the vector (array) a is negated.
Output from the test program splVNg3.c:
Resultant Components:
b[0] = -1.234000
b[1] = 0.678000
b[3] = -10.300000