/*
 * File: sum.c
 *
 * MATLAB Coder version            : 3.4
 * C/C++ source code generated on  : 27-Feb-2019 07:49:44
 */

/* Include Files */
#include "rt_nonfinite.h"
#include "MLS.h"
#include "sum.h"

/* Function Definitions */

/*
 * Arguments    : const emxArray_real_T *x
 *                double y[2]
 * Return Type  : void
 */
void b_sum(const emxArray_real_T *x, double y[2])
{
  int i;
  int xpageoffset;
  int k;
  if (x->size[0] == 0) {
    for (i = 0; i < 2; i++) {
      y[i] = 0.0;
    }
  } else {
    for (i = 0; i < 2; i++) {
      xpageoffset = i * x->size[0];
      y[i] = x->data[xpageoffset];
      for (k = 2; k <= x->size[0]; k++) {
        y[i] += x->data[(xpageoffset + k) - 1];
      }
    }
  }
}

/*
 * Arguments    : const emxArray_real_T *x
 * Return Type  : double
 */
double sum(const emxArray_real_T *x)
{
  double y;
  int k;
  if (x->size[0] == 0) {
    y = 0.0;
  } else {
    y = x->data[0];
    for (k = 2; k <= x->size[0]; k++) {
      y += x->data[k - 1];
    }
  }

  return y;
}

/*
 * File trailer for sum.c
 *
 * [EOF]
 */
