#if !defined  HAVE_QUANTIZE_H__
#define       HAVE_QUANTIZE_H__

#include "fxttypes.h"

#include <cmath> // floor()


template  <typename Type>
void quantize(Type *f, ulong n, double q)
// In f[] set each element x to q*floor(1/q*(x+q/2))
// E.g.: q=1 ==> round to nearest integer
//       q=1/1000 ==> round to nearest multiple of 1/1000
// For inexact types (float or double).
{
    Type qh = q * 0.5;
    Type q1 = 1.0 / q;
    while ( n-- )
    {
        f[n] = q * floor( q1 * (f[n]+qh) );
    }
}
// -------------------------


#endif  // !defined HAVE_QUANTIZE_H__
