
    /***********************************************************************
                   Copyright (c) 2007 SKY Computers, Inc.

     Redistribution and use in source and binary forms are permitted
     provided that this notice is preserved and that due credit is given to
     SKY Computers, Inc. The name of SKY Computers, Inc. may not be used to
     endorse or promote products derived from this software without
     specific prior written permission. This software is provided ``as is''
     without express or implied warranty.
    ************************************************************************/
    
/*
 *--------------------------------------------------------------------------
 *
 >++
 *
 *   File: ex_math.c 
 *
 *   Function: To provide some functions for the TimeTrac example programs.
 *
 *   Calling Sequence: See below.
 *  
 *   Implementation Details:
 *       1. These are simple vector math functions that will consume some
 *          amount of CPU time, depending on vector length.
 *
 *   Restrictions:
 *       1. There is no input parameter validation.
 *
 >**
 *   Revision Information:
 *    Date       By   Rev    Changes Made....
 *    11/02/07   bwj  ----   New Module.
 *
 >--
 *--------------------------------------------------------------------------
 */
 
#include "sky_ex_inc.h"

/* ---------------------------------------------------------------------- */ 

/*
 >++
 *
 *   void vadd (float *a, float *b, float *r, int n):
 *       float *a: Pointer to an array of single precision values to be
 *           used as the first input.
 *       float *b: Pointer to an array of single precision values to be
 *           used as the second input.
 *       float *r: Pointer to an array of single precision values to be
 *           used as resultant output.
 *       int n: Number of elements in the arrays.
 *     
 *       Given the 2 input arrays the out is an array of the sum of the
 *           two inputs:
 *                a[i] + b[i] = r[i]
 *
 *       Returns: 0 on success. 
 >--
 */

int vadd (float *a, float *b, float *r, int n)
{   
  int i;

  for (i = 0; i < n; i++)
    {
      r[i] = a[i] + b[i];
    }
} 
  
/* ---------------------------------------------------------------------- */ 

/*
 >++
 *
 *   void vmul (float *a, float *b, float *r, int n):
 *       float *a: Pointer to an array of single precision values to be
 *           used as the first input.
 *       float *b: Pointer to an array of single precision values to be
 *           used as the second input.
 *       float *r: Pointer to an array of single precision values to be
 *           used as resultant output.
 *       int n: Number of elements in the arrays.
 *     
 *       Given the 2 input arrays the out is an array of the product of the
 *           two inputs:
 *                a[i] * b[i] = r[i]
 *
 *       Returns: 0 on success. 
 >--
 */

void vmul (float *a, float *b, float *r, int n)
{
  int i;

  for (i = 0; i < n; i++)
    {
      r[i] = a[i] * b[i];
    }
}

/* ---------------------------------------------------------------------- */ 

/*
 >++
 *
 *   void vsub (float *a, float *b, float *r, int n):
 *       float *a: Pointer to an array of single precision values to be
 *           used as the first input.
 *       float *b: Pointer to an array of single precision values to be
 *           used as the second input.
 *       float *r: Pointer to an array of single precision values to be
 *           used as resultant output.
 *       int n: Number of elements in the arrays.
 *     
 *       Given the 2 input arrays the out is an array of the difference 
 *           of the two inputs:
 *                a[i] - b[i] = r[i]
 *
 *       Returns: 0 on success. 
 >--
 */

void vsub (float *a, float *b, float *r, int n)
{
  int i;

  for (i = 0; i < n; i++)
    {
      r[i] = a[i] - b[i];
    }
}

/* ---------------------------------------------------------------------- */ 

/*
 >++
 *
 *   void vinput (float *r, int n):
 *       float *r: Pointer to an array of single precision values to be
 *           used as resultant output.
 *       int n: Number of elements in the arrays.
 *     
 *       Creates an array of data values that consist of a scaled ramp.
 *                r[i] = i * constant
 *
 *       Returns: 0 on success. 
 >--
 */

void vinput (float *r, int n)
{
  int i;

  for (i = 0; i < n; i++)
    {
      r[i] = (float) i * 0.3333;
    }
}

/* ---------------------------------------------------------------------- */ 

/*
 >++
 *
 *   void vsum (float *a, float *b, float *r, int n):
 *       float *a: Pointer to an array of single precision values to be
 *           used as the first input.
 *       float *b: Pointer to an array of single precision values to be
 *           used as the second input.
 *       float *r: Pointer to an array of single precision values to be
 *           used as resultant output.
 *       int n: Number of elements in the arrays.
 *     
 *       Given the 2 input arrays the out is an array of the sum of the
 *           two inputs:
 *                a[i] + b[i] = r[i]
 *
 *       Returns: 0 on success. 
 >--
 */

void vsum (float *s1, float *s2, float *r, int n)
{
  int i;

  for (i = 0; i < n; i++)
    {
      r[i] = s1[i] + s2[i];
    }
}

/* --------------------------- End of Module ---------------------------- */
 

