/// tkmath.h
///
/// (c) 2008 by Carsten Busse <carsten.busse@googlemail.com>,
///             Bastian Spiegel <bs@tkscript.de>
///     - Distributed under terms of the Lesser GNU General Public License (LGPL).
///       See COPYING and <http://www.gnu.org/licenses/licenses.html#LGPL> for further information.
///
///

#ifndef __TKMATH_H_
#define __TKMATH_H

/* @beginmodule tkmath

TkMath - Basic mathematical objects and methods

 */

#ifdef USE_DYNAMIC_ORDER
// Element order is configurable per Object
#define M4(a, row, col)  matrix4_element_order_table[(a)->b_column_major][row][col]
#define M3(a, row, col)  matrix3_element_order_table[(a)->b_column_major][row][col]
#define M2(a, row, col)  matrix2_element_order_table[(a)->b_column_major][row][col]

#if 0
#define M4(a, row, col) ((a)->b_column_major ? (((col)<<2)+(row)) : (((row)<<2)+(col)))
#define M3(a, row, col) ((a)->b_column_major ? (((col)<<1)+(col)+(row)) : (((row)<<1)+(row)+(col)))
#define M2(a, row, col) ((a)->b_column_major ? (((col)<<1)+(row)) : (((row)<<1)+(col)))
#endif // 0

extern const sU8 matrix4_element_order_table[2][4][4];
extern const sU8 matrix3_element_order_table[2][3][3];
extern const sU8 matrix2_element_order_table[2][2][2];

#else
// Always column major
#define M4(a, row, col) (((col)<<2)+(row))
#define M3(a, row, col) ((col<<1)+(col)+(row))
#define M2(a, row, col) (((col)<<1)+(col)+(row))
#endif // USE_DYNAMIC_ORDER


#define TM4(row, col)  M4(this,row,col)
#define TM3(row, col)  M3(this,row,col)
#define TM2(row, col)  M2(this,row,col)

#define OM4(row, col)  M4(o,row,col)
#define OM3(row, col)  M3(o,row,col)
#define OM2(row, col)  M2(o,row,col)


#include "commonmath.h" //this is needed for all

Dyac_std_exid_decl;

Dyac_exid_decl(TkMathError);
Dyac_exid_decl(TkMathDivisionByZero);
Dyac_exid_decl(TkMathInvalidValue);
Dyac_exid_decl(TkMathUnsupportedOperator);


#ifndef HAVE_HYPOTF
extern float hypotf_emul(float x, float y);
#endif //HAVE_HYPOTF


#endif // __TKMATH_H__

