Skip to content

Commit 2bcc907

Browse files
author
camilo
committed
refactor inf/nan values
1 parent ff141e1 commit 2bcc907

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

include/qffmath.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C" {
4747
#define QLIB_ISINF qFFMath_IsInf
4848
#define QLIB_MAX qFFMath_Max
4949
#define QLIB_MIN qFFMath_Min
50-
#define QLIB_NAN QFFM_NAN
50+
#define QLIB_NAN ( qFFMath_NotANumber[ 0 ] )
5151
#define QLIB_FMOD qFFMath_Mod
5252
#define QLIB_ROUND qFFMath_Round
5353
/*! @endcond */
@@ -58,10 +58,6 @@ extern "C" {
5858
* @{
5959
*/
6060

61-
/*! @cond */
62-
float _qFFMath_GetAbnormal( const int i ); //skipcq: CXX-E2000
63-
/*! @endcond */
64-
6561
/** @brief The base of natural logarithms ( e ) given as a single-precision floating-point number*/
6662
#define QFFM_E ( 2.7182818284590452354F )
6763
/** @brief The base 2 logarithm of e ( log_2 e ) given as a single-precision floating-point number */
@@ -101,9 +97,9 @@ extern "C" {
10197
/** @brief The maximum value of a non-infinite single-precision floating-point number */
10298
#define QFFM_MAXFLOAT ( 3.40282347e+38F )
10399
/** @brief Positive infinity given as a single-precision floating-point number */
104-
#define QFFM_INFINITY _qFFMath_GetAbnormal( 0 )
100+
#define QFFM_INFINITY ( qFFMath_Infinity[ 0 ] )
105101
/** @brief Not a Number (NaN) given as a single-precision floating-point number */
106-
#define QFFM_NAN _qFFMath_GetAbnormal( 1 )
102+
#define QFFM_NAN ( qFFMath_NotANumber[ 0 ] )
107103

108104
/** @brief Indicates that the value is positive or negative zero */
109105
#define QFFM_FP_ZERO ( 0 )
@@ -1010,6 +1006,12 @@ extern "C" {
10101006
float qFFMath_Sph_legendre( size_t l,
10111007
size_t m,
10121008
float theta );
1009+
1010+
/*! @cond */
1011+
extern const float * const qFFMath_Infinity;
1012+
extern const float * const qFFMath_NotANumber;
1013+
/*! @endcond */
1014+
10131015
#endif /*#ifdef QLIBS_USE_STD_MATH*/
10141016

10151017
/** @}*/

include/qinterp1.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ extern "C" {
3434
QINTERP1_HERMITE, /*!< Piecewise cubic Hermite interpolation.*/
3535
QINTERP1_SPLINE, /*!< Catmull spline interpolation.*/
3636
QINTERP1_CONSTRAINED_SPLINE, /*!< A special kind of spline that doesn't overshoot.*/
37+
/*! @cond */
3738
QINTERP1_MAX,
39+
/*! @endcond */
3840
} qInterp1Method_t;
3941

4042

qffmath.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
#include <string.h>
1212
#include <float.h>
1313

14+
static const union {
15+
uint32_t u[ 2 ];
16+
float f[ 2 ];
17+
} s_values = { { 0x7F800000U, 0x7FBFFFFFU } };
18+
const float * const qFFMath_Infinity = &s_values.f[ 0 ];
19+
const float * const qFFMath_NotANumber = &s_values.f[ 1 ];
20+
1421
/*cppcheck-suppress misra-c2012-20.7 */
1522
#define cast_reinterpret( dst, src, dst_type ) \
1623
(void)memcpy( &dst, &src, sizeof(dst_type) ) \
@@ -78,21 +85,6 @@ static float cyl_bessel_ij_series( float nu,
7885
float sgn,
7986
size_t max_iter );
8087

81-
/*============================================================================*/
82-
float _qFFMath_GetAbnormal( const int i )
83-
{
84-
static const uint32_t u_ab[ 2 ] = { 0x7F800000U, 0x7FBFFFFFU };
85-
static float f_ab[ 2 ] = { 0.0F, 0.0F };
86-
static bool init = true;
87-
88-
if ( init ) {
89-
/*cppcheck-suppress misra-c2012-21.15 */
90-
(void)memcpy( f_ab, u_ab, sizeof(f_ab) );
91-
init = false;
92-
}
93-
94-
return f_ab[ i ];
95-
}
9688
/*============================================================================*/
9789
int qFFMath_FPClassify( const float f )
9890
{
@@ -1511,7 +1503,7 @@ float qFFMath_Beta( float x,
15111503
{
15121504
float result;
15131505
/*cstat -MISRAC2012-Rule-13.5*/
1514-
if ( qFFMath_IsNaN( x ) || qFFMath_IsNaN( y ) ) { //no side effects here
1506+
if ( qFFMath_IsNaN( x ) || qFFMath_IsNaN( y ) ) { /*no side effects*/
15151507
result = QFFM_NAN;
15161508
}
15171509
else {
@@ -1808,7 +1800,7 @@ float qFFMath_Comp_ellint_3( float k,
18081800
{
18091801
float y;
18101802
/*cstat -MISRAC2012-Rule-13.5*/
1811-
if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( nu ) || ( qFFMath_Abs( k ) > 1.0F ) ) { //no side effects here
1803+
if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( nu ) || ( qFFMath_Abs( k ) > 1.0F ) ) { /*no side effects*/
18121804
y = QFFM_NAN;
18131805
}
18141806
else if ( qFFMath_IsEqual( 1.0F, nu ) ) {
@@ -1829,7 +1821,7 @@ float qFFMath_Ellint_1( float k,
18291821
{
18301822
float y;
18311823
/*cstat -MISRAC2012-Rule-13.5*/
1832-
if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { //no side effects here
1824+
if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { /*no side effects*/
18331825
y = QFFM_NAN;
18341826
}
18351827
else {
@@ -1854,7 +1846,7 @@ float qFFMath_Ellint_2( float k,
18541846
{
18551847
float y;
18561848
/*cstat -MISRAC2012-Rule-13.5*/
1857-
if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { //no side effects here
1849+
if ( qFFMath_IsNaN( k ) || qFFMath_IsNaN( phi ) || ( qFFMath_Abs( k ) > 1.0F ) ) { /*no side effects*/
18581850
y = QFFM_NAN;
18591851
}
18601852
else {

0 commit comments

Comments
 (0)