/* ##H_FILE# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FILE : MTH_fchk.h MODULE : MTH (Common Mathematic Library) DESCRIPTION : Checking utilities for NAN float numbers VERSION : MTH V5.0.13 / Alexandre LANGER [ALX] Ubi R&D / Add Comments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ##INCLUDE#---------------------------------------------------------------------------- Includes Files ---------------------------------------------------------------------------------------*/ #include #ifndef MTH_FCHK_H #define MTH_FCHK_H #include "acp_base.h" /* ##MACRO#---------------------------------------------------------------------------- MACRO definition ---------------------------------------------------------------------------------------*/ /* ##M================================================================================== NAME : MTH_M_vCHK DESCRIPTION : Make a break on NAN (not a number) INPUT : a : float OUTPUT : void =======================================================================================*/ /* Checking for NAN or Infinite Numbers */ #ifdef VISUAL #define MTH_M_vCHK(X) \ { \ if( ( *(long *)&(X) & 0x7F800000)==0x7F800000 ) \ { \ _asm{ \ int 3 \ } \ } \ } #else /* OTHERS */ #define MTH_M_vCHK(X) \ assert( !( ( *(long *)&(X) & 0x7F800000)==0x7F800000) ) #endif /* VISUAL OR OTHERS */ /* ##FUNCDEF#---------------------------------------------------------------------------- Functions definition ---------------------------------------------------------------------------------------*/ /* ##F================================================================================== NAME : MTH_fn_xRealToLongRoundCHK DESCRIPTION : Return long round of a real number with NAN check INPUT : a : MTH_tdxReal OUTPUT : round(a) : long =======================================================================================*/ INLINE long MTH_CALL MTH_fn_xRealToLongRoundCHK(float f) { MTH_M_vCHK(f); return ( (long) ( (long)(f*2.0F)-(long)(f) ) ); } /* ##F================================================================================== NAME : MTH_fn_xAddCHK DESCRIPTION : Return the addition of two real numbers with NAN check INPUT : a, b : 2 MTH_tdxReal OUTPUT : a + b : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xAddCHK(float a, float b) { float res; MTH_M_vCHK(a); MTH_M_vCHK(b); res= a + b; MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xSubCHK DESCRIPTION : Return the subtraction of two real numbers with NAN check INPUT : a, b : 2 MTH_tdxReal OUTPUT : a - b : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xSubCHK(float a, float b) { float res; MTH_M_vCHK(a); MTH_M_vCHK(b); res= a - b; MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xMulCHK DESCRIPTION : Return the multiply of two real numbers with NAN check INPUT : a, b : 2 MTH_tdxReal OUTPUT : a * b : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xMulCHK(float a, float b) { float res; MTH_M_vCHK(a); MTH_M_vCHK(b); res= a * b; MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xDivCHK DESCRIPTION : Return the division of two real numbers with NAN check INPUT : a, b : 2 MTH_tdxReal OUTPUT : a / b : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xDivCHK(float a, float b) { float res; MTH_M_vCHK(a); MTH_M_vCHK(b); res= a / b; MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xNegCHK DESCRIPTION : Return the negation of a real number with NAN check INPUT : a : MTH_tdxReal OUTPUT : -a : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xNegCHK(float a) { float res; MTH_M_vCHK(a); res= -a; MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xSqrCHK DESCRIPTION : Return the square of a real number with NAN check INPUT : a : MTH_tdxReal OUTPUT : a*a : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xSqrCHK(float a) { float res; MTH_M_vCHK(a); res= a * a; MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xSqrtCHK DESCRIPTION : Return the square root of a real number with NAN check INPUT : a : MTH_tdxReal OUTPUT : sqrt(a) : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xSqrtCHK(float a) { float res; MTH_M_vCHK(a); res= ( (float) sqrt((double) (a)) ); MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xInvSqrtCHK DESCRIPTION : Return the inverse of the square root of a real number with NAN check INPUT : a : MTH_tdxReal OUTPUT : 1/sqrt(a) : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xInvSqrtCHK(float a) { float res; MTH_M_vCHK(a); res= 1.0F / ( (float) sqrt((double) (a)) ); MTH_M_vCHK(res); return (res); } /* ##F================================================================================== NAME : MTH_fn_xInvCHK DESCRIPTION : Return the inverse of a real number with NAN check INPUT : a : MTH_tdxReal OUTPUT : 1/a : MTH_tdxReal =======================================================================================*/ INLINE float MTH_CALL MTH_fn_xInvCHK(float a) { float res; MTH_M_vCHK(a); res= 1.0F / a; MTH_M_vCHK(res); return (res); } #endif /* MTH_FCHK_H */