/**************************************************/
/*  Round off each sample to specified tolerance  */
/**************************************************/
#include "Round.h"
#include <stdio.h>
#include <math.h>

Round :: Round(double aErr)
{
  Err = aErr;
}

Round :: ~Round()
{
}

void Round :: setErr(double aErr)
{
  Err = aErr;
}

double Round :: tick(double soundin, double *errout)
{
  double out;

  if (Err < 2.0 * DBL_EPSILON) {
    *errout = 0.0;
    return soundin;
  } else {
    out = (floor(soundin * 2.0 / Err + 0.5) - 0.5) * Err / 2.0;
    *errout = out - soundin;
    return (out);
  }
}
