/* Fixed point math format conversion code V1.20 24/9/03
   Needs fixmath.c/fixmath.h to work
   Copyright 2008 Jeffrey Lee
   This file is part of WOUM.
   WOUM is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   WOUM is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with WOUM.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _FIXMATH_CONV_H
#define _FIXMATH_CONV_H

#include "fixmath.h"

/* Need conversions between:
   int
   float
   f1616
   f2012
   f248
   f4816
   I.e. 36 functions
*/

#define int_to_int(a) ((int) (a))
#define int_to_float(a) ((float) (a))
#define int_to_f1616(a) (f1616_FromInt(a))
#define int_to_f2012(a) (f2012_FromInt(a))
#define int_to_f248(a) (f248_FromInt(a))
#define int_to_f4816(a) (f4816_FromInt(a))

#define float_to_int(a) ((int) (a))
#define float_to_float(a) ((float) (a))
#define float_to_f1616(a) (f1616_FromFloat(a))
#define float_to_f2012(a) (f2012_FromFloat(a))
#define float_to_f248(a) (f248_FromFloat(a))
#define float_to_f4816(a) (f4816_FromFloat(a))

#define f1616_to_int(a) (f1616_ToInt(a))
#define f1616_to_float(a) (f1616_ToFloat(a))
#define f1616_to_f1616(a) (a)
#define f1616_to_f2012(a) ((f2012) ((a) >> 4))
#define f1616_to_f248(a) ((f248) ((a) >> 8))
#define f1616_to_f4816(a) ((f4816) (a))

#define f2012_to_int(a) (f2012_ToInt(a))
#define f2012_to_float(a) (f2012_ToFloat(a))
#define f2012_to_f1616(a) ((f1616) ((a) << 4))
#define f2012_to_f2012(a) (a)
#define f2012_to_f248(a) ((f248) ((a) >> 4))
#define f2012_to_f4816(a) (((f248) (a)) << 4)

#define f248_to_int(a) (f248_ToInt(a))
#define f248_to_float(a) (f248_ToFloat(a))
#define f248_to_f1616(a) ((f1616) ((a) << 8))
#define f248_to_f2012(a) ((f2012) ((a) << 4))
#define f248_to_f248(a) (a)
#define f248_to_f4816(a) (((f4816) (a)) << 8)

#define f4816_to_int(a) (f4816_ToInt(a))
#define f4816_to_float(a) (f4816_ToFloat(a))
#define f4816_to_f1616(a) ((f1616) (a))
#define f4816_to_f2012(a) ((f2012) ((a) >> 4))
#define f4816_to_f248(a) ((f248) ((a) >> 8))
#define f4816_to_f4816(a) (a)

#define _fix_op(Type,Func,Args...) Type ## Func(Args)
#define fix_op(Type,Func,Args...) _fix_op(Type,Func,Args)
#define _conv_op(FromType,ToType,Val) FromType ## _to_ ## ToType(Val)
#define conv_op(FromType,ToType,Val) _conv_op(FromType,ToType,Val)

#endif
