#include "bsp_1_d.h"

#include <cassert>       // assert()
#include <cmath>

using namespace std;

double scalar(vector<double> const &x, vector<double> const &y)
{
    assert(x.size() == y.size()); // switch off via compile flag: -DNDEBUG
    size_t const N = x.size();
    double sum = 0.0;
    for (size_t i = 0; i < N; ++i)
    {
        sum += x[i] * y[i];
    }
    return sum;
}

double Kahan_skalar(vector<double> const &x, vector<double> const &y)
{
    assert(x.size() == y.size()); // switch off via compile flag: -DNDEBUG
    size_t const N = x.size();
    double sum = 0.0;
    double c = 0.0;
    for (size_t i = 0; i < N; ++i)
    {
        double z = x[i]*y[i] - c;
        double t = sum + z;
        c = (t - sum) - z;
        sum = t;
    }
    return sum;
}
