/*
 *
 *
 *    ops.h
 *
 *    Standardized operations.
 *
 *    Copyright (C) 2016 by Matt Roberts.
 *    License: GNU GPL3 (www.gnu.org)
 *
 *
 */

#ifndef __KK5JY_OPS_H
#define __KK5JY_OPS_H

#include <math.h>
#include <stdint.h>

namespace KK5JY {
	namespace DSP {
		//
		//  class Operations<T>
		//
		template <typename T>
		class Operations {
			public:
				// absolute value
				static T absv(T value) { return abs(value); }

				// closest value
				static T closest(T value) { return round(value); }

				// fast division
				static T div2(T value) { return value >> 1; };
				static T div4(T value) { return value >> 2; };
		};

		//
		//  absv
		//
		template<>
		inline double Operations<double>::absv(double value) { return fabs(value); }

		template<>
		inline float Operations<float>::absv(float value) { return fabs(value); }

		//
		//  closest
		//
		template<>
		inline double Operations<double>::closest(double value) { return value; }

		template<>
		inline float Operations<float>::closest(float value) { return value; }

		//
		//  div2
		//
		template<>
		inline double Operations<double>::div2(double value) { return value * 0.5L; }

		template<>
		inline float Operations<float>::div2(float value) { return value * 0.5; }

		//
		//  div4
		//
		template<>
		inline double Operations<double>::div4(double value) { return value * 0.25L; }

		template<>
		inline float Operations<float>::div4(float value) { return value * 0.25; }
	}
}

#endif
