Matrix fix
Posted: Sat Sep 06, 2014 5:14 am
hm... Maybe I forgot to report this, as I couldn't find it in the forum-search.
When using CMatrix<f64>, an error arises in function CMatrix4<T>::getInverse(CMatrix4<T>& out). The line of code with the error is 1330 where it says: if( core::iszero ( d, FLT_MIN ) ).
The problem is that FLT_MIN is floating point and "d" is double, resulting in the compiler not knowing what iszero() to use (or at least it gave me grief, of all people). For that, I created iszeroT( const T a, const T tolerance = 0 ) and I cast the FLT_MIN to (T). Yeah, it's not exactly correct, but c++ doesn't have type checking.
As a proposed fix to the matrix problem, we could add an enum for a parameter that allows the user to set what tolerances they want to use when comparing values. The defaults will be float, but at least the user has more control over getting the correct value. Plus, a param for this enum could be placed at the end of the parameter list in the constructors, set to the default of float.
When using CMatrix<f64>, an error arises in function CMatrix4<T>::getInverse(CMatrix4<T>& out). The line of code with the error is 1330 where it says: if( core::iszero ( d, FLT_MIN ) ).
The problem is that FLT_MIN is floating point and "d" is double, resulting in the compiler not knowing what iszero() to use (or at least it gave me grief, of all people). For that, I created iszeroT( const T a, const T tolerance = 0 ) and I cast the FLT_MIN to (T). Yeah, it's not exactly correct, but c++ doesn't have type checking.
Code: Select all
template<class T>
inline bool iszeroT( const T a, const T tolerance = 0 )
{
return abs_(a) < tolerance;
}
Code: Select all
enum EMatrixTolerance
{
EMTOL_NONE, // no tolerance
EMTOL_F32,
EMTOL_F64
} matrixTolerance;
// usage as in the problem I presented...
switch( matrixTolerance )
{
case EMTOL_NONE: if ( iszero( (s32)d ) ) return false; break;
case EMTOL_F32: if ( iszero( (f32)d, FLT_MIN ) return false; break;
case EMTOL_F64: if ( iszero( (f64)d, DBL_MIN ) return false; break;
}