diff --git a/include/qffmath.h b/include/qffmath.h index d5e1a70..0d94ae0 100644 --- a/include/qffmath.h +++ b/include/qffmath.h @@ -47,7 +47,7 @@ extern "C" { #define QLIB_ISINF qFFMath_IsInf #define QLIB_MAX qFFMath_Max #define QLIB_MIN qFFMath_Min - #define QLIB_NAN QFFM_NAN + #define QLIB_NAN ( qFFMath_NotANumber[ 0 ] ) #define QLIB_FMOD qFFMath_Mod #define QLIB_ROUND qFFMath_Round /*! @endcond */ @@ -58,10 +58,6 @@ extern "C" { * @{ */ - /*! @cond */ - float _qFFMath_GetAbnormal( const int i ); //skipcq: CXX-E2000 - /*! @endcond */ - /** @brief The base of natural logarithms ( e ) given as a single-precision floating-point number*/ #define QFFM_E ( 2.7182818284590452354F ) /** @brief The base 2 logarithm of e ( log_2 e ) given as a single-precision floating-point number */ @@ -101,9 +97,9 @@ extern "C" { /** @brief The maximum value of a non-infinite single-precision floating-point number */ #define QFFM_MAXFLOAT ( 3.40282347e+38F ) /** @brief Positive infinity given as a single-precision floating-point number */ - #define QFFM_INFINITY _qFFMath_GetAbnormal( 0 ) + #define QFFM_INFINITY ( qFFMath_Infinity[ 0 ] ) /** @brief Not a Number (NaN) given as a single-precision floating-point number */ - #define QFFM_NAN _qFFMath_GetAbnormal( 1 ) + #define QFFM_NAN ( qFFMath_NotANumber[ 0 ] ) /** @brief Indicates that the value is positive or negative zero */ #define QFFM_FP_ZERO ( 0 ) @@ -1010,6 +1006,12 @@ extern "C" { float qFFMath_Sph_legendre( size_t l, size_t m, float theta ); + + /*! @cond */ + extern const float * const qFFMath_Infinity; + extern const float * const qFFMath_NotANumber; + /*! @endcond */ + #endif /*#ifdef QLIBS_USE_STD_MATH*/ /** @}*/ diff --git a/include/qinterp1.h b/include/qinterp1.h index f67030a..29a2bc8 100644 --- a/include/qinterp1.h +++ b/include/qinterp1.h @@ -34,7 +34,9 @@ extern "C" { QINTERP1_HERMITE, /*!< Piecewise cubic Hermite interpolation.*/ QINTERP1_SPLINE, /*!< Catmull spline interpolation.*/ QINTERP1_CONSTRAINED_SPLINE, /*!< A special kind of spline that doesn't overshoot.*/ + /*! @cond */ QINTERP1_MAX, + /*! @endcond */ } qInterp1Method_t; diff --git a/qffmath.c b/qffmath.c index fa32bf1..fc96e1c 100644 --- a/qffmath.c +++ b/qffmath.c @@ -11,6 +11,13 @@ #include #include +static const union { + uint32_t u[ 2 ]; + float f[ 2 ]; +} s_values = { { 0x7F800000U, 0x7FBFFFFFU } }; +const float * const qFFMath_Infinity = &s_values.f[ 0 ]; +const float * const qFFMath_NotANumber = &s_values.f[ 1 ]; + /*cppcheck-suppress misra-c2012-20.7 */ #define cast_reinterpret( dst, src, dst_type ) \ (void)memcpy( &dst, &src, sizeof(dst_type) ) \ @@ -78,21 +85,6 @@ static float cyl_bessel_ij_series( float nu, float sgn, size_t max_iter ); -/*============================================================================*/ -float _qFFMath_GetAbnormal( const int i ) -{ - static const uint32_t u_ab[ 2 ] = { 0x7F800000U, 0x7FBFFFFFU }; - static float f_ab[ 2 ] = { 0.0F, 0.0F }; - static bool init = true; - - if ( init ) { - /*cppcheck-suppress misra-c2012-21.15 */ - (void)memcpy( f_ab, u_ab, sizeof(f_ab) ); - init = false; - } - - return f_ab[ i ]; -} /*============================================================================*/ int qFFMath_FPClassify( const float f ) { @@ -1511,7 +1503,7 @@ float qFFMath_Beta( float x, { float result; /*cstat -MISRAC2012-Rule-13.5*/ - if ( qFFMath_IsNaN( x ) || qFFMath_IsNaN( y ) ) { //no side effects here + if ( qFFMath_IsNaN( x ) || qFFMath_IsNaN( y ) ) { /*no side effects*/ result = QFFM_NAN; } else { @@ -1808,7 +1800,7 @@ float qFFMath_Comp_ellint_3( float k, { float y; /*cstat -MISRAC2012-Rule-13.5*/ - if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( nu ) || ( qFFMath_Abs( k ) > 1.0F ) ) { //no side effects here + if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( nu ) || ( qFFMath_Abs( k ) > 1.0F ) ) { /*no side effects*/ y = QFFM_NAN; } else if ( qFFMath_IsEqual( 1.0F, nu ) ) { @@ -1829,7 +1821,7 @@ float qFFMath_Ellint_1( float k, { float y; /*cstat -MISRAC2012-Rule-13.5*/ - if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { //no side effects here + if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { /*no side effects*/ y = QFFM_NAN; } else { @@ -1854,7 +1846,7 @@ float qFFMath_Ellint_2( float k, { float y; /*cstat -MISRAC2012-Rule-13.5*/ - if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { //no side effects here + if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { /*no side effects*/ y = QFFM_NAN; } else {