From 3e3be94b5f4a8a265a2ed7ff1e43fb2e8af8a8c8 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 14:57:00 +0200 Subject: [PATCH 1/7] Improve self-written header --- .../app_benchmark_boost_math_cyl_bessel_j.cpp | 9 - .../src/app/benchmark/app_benchmark_detail.h | 28 +- ref_app/src/util/STL/cmath | 1104 +++++++++-------- 3 files changed, 596 insertions(+), 545 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_boost_math_cyl_bessel_j.cpp b/ref_app/src/app/benchmark/app_benchmark_boost_math_cyl_bessel_j.cpp index b037a9c35..a9e4ef704 100644 --- a/ref_app/src/app/benchmark/app_benchmark_boost_math_cyl_bessel_j.cpp +++ b/ref_app/src/app/benchmark/app_benchmark_boost_math_cyl_bessel_j.cpp @@ -36,11 +36,6 @@ extern "C" #include -#if defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wall" -#endif - //#define APP_BENCHMARK_TYPE_BOOST_MATH_CBRT_TGAMMA_EXCLUDES_TGAMMA #if !defined(BOOST_MATH_STANDALONE) @@ -154,8 +149,4 @@ my_float_type cyj; unsigned xn = static_cast(UINT8_C(1)); my_float_type v = static_cast(BOOST_FLOATMAX_C(1.23)); -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - #endif // APP_BENCHMARK_TYPE_BOOST_MATH_CYL_BESSEL_J diff --git a/ref_app/src/app/benchmark/app_benchmark_detail.h b/ref_app/src/app/benchmark/app_benchmark_detail.h index c1dd3e636..201c269f4 100644 --- a/ref_app/src/app/benchmark/app_benchmark_detail.h +++ b/ref_app/src/app/benchmark/app_benchmark_detail.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2024. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -14,15 +14,31 @@ namespace app { namespace benchmark { namespace detail { template - auto is_close_fraction(const NumericType a, // NOLINT(bugprone-easily-swappable-parameters) - const NumericType b, // NOLINT(bugprone-easily-swappable-parameters) - const NumericType tol = NumericType(std::numeric_limits::epsilon() * NumericType(100))) -> bool + constexpr auto default_tol() noexcept -> NumericType + { + return NumericType { std::numeric_limits::epsilon() * NumericType(100) }; + } + + template + constexpr auto is_close_fraction(const NumericType a, // NOLINT(bugprone-easily-swappable-parameters) + const NumericType b, // NOLINT(bugprone-easily-swappable-parameters) + const NumericType tol = default_tol()) noexcept -> bool { using std::fabs; + using std::fpclassify; + + NumericType closeness { }; - const NumericType ratio = fabs(NumericType((NumericType(1) * a) / b)); + if(fpclassify(b) == FP_ZERO) + { + closeness = fabs(a - b); + } + else + { + const NumericType ratio = a / b; - const NumericType closeness = fabs(NumericType(1 - ratio)); + closeness = NumericType { fabs(NumericType { 1 - ratio }) }; + } return (closeness < tol); } diff --git a/ref_app/src/util/STL/cmath b/ref_app/src/util/STL/cmath index eac52f2ba..b6b383e59 100644 --- a/ref_app/src/util/STL/cmath +++ b/ref_app/src/util/STL/cmath @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2024. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -9,6 +9,7 @@ #define CMATH_2010_02_23_ #include + #include // Implement most of for compilers that do not yet support it. @@ -58,169 +59,169 @@ "Error: Configuration error regarding 64-bit double/long-double for AVR"); #if(__SIZEOF_DOUBLE__ == 4) - #define __BUILTIN_ISNANF __builtin_isnan - #define __BUILTIN_ISNAN __builtin_isnan - #define __BUILTIN_ISNANL __builtin_isnanl - #define __BUILTIN_FABSF __builtin_fabs - #define __BUILTIN_FABS __builtin_fabs - #define __BUILTIN_FABSL __builtin_fabsl - #define __BUILTIN_FMODF __builtin_fmod - #define __BUILTIN_FMOD __builtin_fmod - #define __BUILTIN_FMODL __builtin_fmodl - #define __BUILTIN_MODFF __builtin_modff - #define __BUILTIN_MODF __builtin_modf - #define __BUILTIN_MODFL __builtin_modfl - #define __BUILTIN_FLOORF __builtin_floor - #define __BUILTIN_FLOOR __builtin_floor - #define __BUILTIN_FLOORL __builtin_floorl - #define __BUILTIN_CEILF __builtin_ceil - #define __BUILTIN_CEIL __builtin_ceil - #define __BUILTIN_CEILL __builtin_ceill - #define __BUILTIN_FREXPF __builtin_frexp - #define __BUILTIN_FREXP __builtin_frexp - #define __BUILTIN_FREXPL __builtin_frexpl - #define __BUILTIN_LDEXPF __builtin_ldexp - #define __BUILTIN_LDEXP __builtin_ldexp - #define __BUILTIN_LDEXPL __builtin_ldexpl - #define __BUILTIN_LROUNDF __builtin_lround - #define __BUILTIN_LROUND __builtin_lround - #define __BUILTIN_LROUNDL __builtin_lroundl - #define __BUILTIN_SQRTF __builtin_sqrt - #define __BUILTIN_SQRT __builtin_sqrt - #define __BUILTIN_SQRTL __builtin_sqrtl - #define __BUILTIN_CBRTF __builtin_cbrt - #define __BUILTIN_CBRT __builtin_cbrt - #define __BUILTIN_CBRTL __builtin_cbrtl - #define __BUILTIN_SINF __builtin_sin - #define __BUILTIN_SIN __builtin_sin - #define __BUILTIN_SINL __builtin_sinl - #define __BUILTIN_COSF __builtin_cos - #define __BUILTIN_COS __builtin_cos - #define __BUILTIN_COSL __builtin_cosl - #define __BUILTIN_TANF __builtin_tan - #define __BUILTIN_TAN __builtin_tan - #define __BUILTIN_TANL __builtin_tanl - #define __BUILTIN_ASINF __builtin_asin - #define __BUILTIN_ASIN __builtin_asin - #define __BUILTIN_ASINL __builtin_asinl - #define __BUILTIN_ACOSF __builtin_acos - #define __BUILTIN_ACOS __builtin_acos - #define __BUILTIN_ACOSL __builtin_acosl - #define __BUILTIN_ATANF __builtin_atan - #define __BUILTIN_ATAN __builtin_atan - #define __BUILTIN_ATANL __builtin_atanl - #define __BUILTIN_ATAN2F __builtin_atan2 - #define __BUILTIN_ATAN2 __builtin_atan2 - #define __BUILTIN_ATAN2L __builtin_atan2l - #define __BUILTIN_EXPF __builtin_exp - #define __BUILTIN_EXP __builtin_exp - #define __BUILTIN_EXPL __builtin_expl - #define __BUILTIN_POWF __builtin_pow - #define __BUILTIN_POW __builtin_pow - #define __BUILTIN_POWL __builtin_powl - #define __BUILTIN_LOGF __builtin_log - #define __BUILTIN_LOG __builtin_log - #define __BUILTIN_LOGL __builtin_logl - #define __BUILTIN_LOG10F __builtin_log10 - #define __BUILTIN_LOG10 __builtin_log10 - #define __BUILTIN_LOG10L __builtin_log10l - #define __BUILTIN_SINHF __builtin_sinh - #define __BUILTIN_SINH __builtin_sinh - #define __BUILTIN_SINHL __builtin_sinhl - #define __BUILTIN_COSHF __builtin_cosh - #define __BUILTIN_COSH __builtin_cosh - #define __BUILTIN_COSHL __builtin_coshl - #define __BUILTIN_TANHF __builtin_tanh - #define __BUILTIN_TANH __builtin_tanh - #define __BUILTIN_TANHL __builtin_tanhl + #define __BUILTIN_ISNANF __builtin_isnan + #define __BUILTIN_ISNAN __builtin_isnan + #define __BUILTIN_ISNANL __builtin_isnanl + #define __BUILTIN_ISINFF __builtin_isinf + #define __BUILTIN_ISINF __builtin_isinf + #define __BUILTIN_ISINFL __builtin_isinfl + #define __BUILTIN_FABSF __builtin_fabs + #define __BUILTIN_FABS __builtin_fabs + #define __BUILTIN_FABSL __builtin_fabsl + #define __BUILTIN_FMODF __builtin_fmod + #define __BUILTIN_FMOD __builtin_fmod + #define __BUILTIN_FMODL __builtin_fmodl + #define __BUILTIN_MODFF __builtin_modff + #define __BUILTIN_MODF __builtin_modf + #define __BUILTIN_MODFL __builtin_modfl + #define __BUILTIN_FLOORF __builtin_floor + #define __BUILTIN_FLOOR __builtin_floor + #define __BUILTIN_FLOORL __builtin_floorl + #define __BUILTIN_CEILF __builtin_ceil + #define __BUILTIN_CEIL __builtin_ceil + #define __BUILTIN_CEILL __builtin_ceill + #define __BUILTIN_FREXPF __builtin_frexp + #define __BUILTIN_FREXP __builtin_frexp + #define __BUILTIN_FREXPL __builtin_frexpl + #define __BUILTIN_LDEXPF __builtin_ldexp + #define __BUILTIN_LDEXP __builtin_ldexp + #define __BUILTIN_LDEXPL __builtin_ldexpl + #define __BUILTIN_LROUNDF __builtin_lround + #define __BUILTIN_LROUND __builtin_lround + #define __BUILTIN_LROUNDL __builtin_lroundl + #define __BUILTIN_SQRTF __builtin_sqrt + #define __BUILTIN_SQRT __builtin_sqrt + #define __BUILTIN_SQRTL __builtin_sqrtl + #define __BUILTIN_CBRTF __builtin_cbrt + #define __BUILTIN_CBRT __builtin_cbrt + #define __BUILTIN_CBRTL __builtin_cbrtl + #define __BUILTIN_SINF __builtin_sin + #define __BUILTIN_SIN __builtin_sin + #define __BUILTIN_SINL __builtin_sinl + #define __BUILTIN_COSF __builtin_cos + #define __BUILTIN_COS __builtin_cos + #define __BUILTIN_COSL __builtin_cosl + #define __BUILTIN_TANF __builtin_tan + #define __BUILTIN_TAN __builtin_tan + #define __BUILTIN_TANL __builtin_tanl + #define __BUILTIN_ASINF __builtin_asin + #define __BUILTIN_ASIN __builtin_asin + #define __BUILTIN_ASINL __builtin_asinl + #define __BUILTIN_ACOSF __builtin_acos + #define __BUILTIN_ACOS __builtin_acos + #define __BUILTIN_ACOSL __builtin_acosl + #define __BUILTIN_ATANF __builtin_atan + #define __BUILTIN_ATAN __builtin_atan + #define __BUILTIN_ATANL __builtin_atanl + #define __BUILTIN_ATAN2F __builtin_atan2 + #define __BUILTIN_ATAN2 __builtin_atan2 + #define __BUILTIN_ATAN2L __builtin_atan2l + #define __BUILTIN_EXPF __builtin_exp + #define __BUILTIN_EXP __builtin_exp + #define __BUILTIN_EXPL __builtin_expl + #define __BUILTIN_POWF __builtin_pow + #define __BUILTIN_POW __builtin_pow + #define __BUILTIN_POWL __builtin_powl + #define __BUILTIN_LOGF __builtin_log + #define __BUILTIN_LOG __builtin_log + #define __BUILTIN_LOGL __builtin_logl + #define __BUILTIN_LOG10F __builtin_log10 + #define __BUILTIN_LOG10 __builtin_log10 + #define __BUILTIN_LOG10L __builtin_log10l + #define __BUILTIN_SINHF __builtin_sinh + #define __BUILTIN_SINH __builtin_sinh + #define __BUILTIN_SINHL __builtin_sinhl + #define __BUILTIN_COSHF __builtin_cosh + #define __BUILTIN_COSH __builtin_cosh + #define __BUILTIN_COSHL __builtin_coshl + #define __BUILTIN_TANHF __builtin_tanh + #define __BUILTIN_TANH __builtin_tanh + #define __BUILTIN_TANHL __builtin_tanhl #elif(__SIZEOF_DOUBLE__ == 8) - #define __BUILTIN_ISNANF __builtin_isnanf - #define __BUILTIN_ISNAN __builtin_isnanl - #define __BUILTIN_ISNANL __builtin_isnanl - #define __BUILTIN_FABSF __builtin_fabsf - #define __BUILTIN_FABS __builtin_fabsl - #define __BUILTIN_FABSL __builtin_fabsl - #define __BUILTIN_FMODF __builtin_fmodf - #define __BUILTIN_FMOD __builtin_fmodl - #define __BUILTIN_FMODL __builtin_fmodl - #define __BUILTIN_MODFF __builtin_modff - #define __BUILTIN_MODF __builtin_modf - #define __BUILTIN_MODFL __builtin_modfl - #define __BUILTIN_FLOORF __builtin_floorf - #define __BUILTIN_FLOOR __builtin_floorl - #define __BUILTIN_FLOORL __builtin_floorl - #define __BUILTIN_CEILF __builtin_ceilf - #define __BUILTIN_CEIL __builtin_ceill - #define __BUILTIN_CEILL __builtin_ceill - #define __BUILTIN_FREXPF __builtin_frexpf - #define __BUILTIN_FREXP __builtin_frexpl - #define __BUILTIN_FREXPL __builtin_frexpl - #define __BUILTIN_LDEXPF __builtin_ldexpf - #define __BUILTIN_LDEXP __builtin_ldexpl - #define __BUILTIN_LDEXPL __builtin_ldexpl - #define __BUILTIN_LROUNDF __builtin_lroundf - #define __BUILTIN_LROUND __builtin_lroundl - #define __BUILTIN_LROUNDL __builtin_lroundl - #define __BUILTIN_SQRTF __builtin_sqrtf - #define __BUILTIN_SQRT __builtin_sqrtl - #define __BUILTIN_SQRTL __builtin_sqrtl - #define __BUILTIN_CBRTF __builtin_cbrtf - #define __BUILTIN_CBRT __builtin_cbrtl - #define __BUILTIN_CBRTL __builtin_cbrtl - #define __BUILTIN_SINF __builtin_sinf - #define __BUILTIN_SIN __builtin_sinl - #define __BUILTIN_SINL __builtin_sinl - #define __BUILTIN_COSF __builtin_cosf - #define __BUILTIN_COS __builtin_cosl - #define __BUILTIN_COSL __builtin_cosl - #define __BUILTIN_TANF __builtin_tanf - #define __BUILTIN_TAN __builtin_tanl - #define __BUILTIN_TANL __builtin_tanl - #define __BUILTIN_ASINF __builtin_asinf - #define __BUILTIN_ASIN __builtin_asinl - #define __BUILTIN_ASINL __builtin_asinl - #define __BUILTIN_ACOSF __builtin_acosf - #define __BUILTIN_ACOS __builtin_acosl - #define __BUILTIN_ACOSL __builtin_acosl - #define __BUILTIN_ATANF __builtin_atanf - #define __BUILTIN_ATAN __builtin_atanl - #define __BUILTIN_ATANL __builtin_atanl - #define __BUILTIN_ATAN2F __builtin_atan2f - #define __BUILTIN_ATAN2 __builtin_atan2l - #define __BUILTIN_ATAN2L __builtin_atan2l - #define __BUILTIN_EXPF __builtin_expf - #define __BUILTIN_EXP __builtin_expl - #define __BUILTIN_EXPL __builtin_expl - #define __BUILTIN_POWF __builtin_powf - #define __BUILTIN_POW __builtin_powl - #define __BUILTIN_POWL __builtin_powl - #define __BUILTIN_LOGF __builtin_logf - #define __BUILTIN_LOG __builtin_logl - #define __BUILTIN_LOGL __builtin_logl - #define __BUILTIN_LOG10F __builtin_log10f - #define __BUILTIN_LOG10 __builtin_log10l - #define __BUILTIN_LOG10L __builtin_log10l - #define __BUILTIN_SINHF __builtin_sinhf - #define __BUILTIN_SINH __builtin_sinhl - #define __BUILTIN_SINHL __builtin_sinhl - #define __BUILTIN_COSHF __builtin_coshf - #define __BUILTIN_COSH __builtin_coshl - #define __BUILTIN_COSHL __builtin_coshl - #define __BUILTIN_TANHF __builtin_tanhf - #define __BUILTIN_TANH __builtin_tanhl - #define __BUILTIN_TANHL __builtin_tanhl + #define __BUILTIN_ISNANF __builtin_isnanf + #define __BUILTIN_ISNAN __builtin_isnanl + #define __BUILTIN_ISNANL __builtin_isnanl + #define __BUILTIN_ISINFF __builtin_isinff + #define __BUILTIN_ISINF __builtin_isinfl + #define __BUILTIN_ISINFL __builtin_isinfl + #define __BUILTIN_FABSF __builtin_fabsf + #define __BUILTIN_FABS __builtin_fabsl + #define __BUILTIN_FABSL __builtin_fabsl + #define __BUILTIN_FMODF __builtin_fmodf + #define __BUILTIN_FMOD __builtin_fmodl + #define __BUILTIN_FMODL __builtin_fmodl + #define __BUILTIN_MODFF __builtin_modff + #define __BUILTIN_MODF __builtin_modf + #define __BUILTIN_MODFL __builtin_modfl + #define __BUILTIN_FLOORF __builtin_floorf + #define __BUILTIN_FLOOR __builtin_floorl + #define __BUILTIN_FLOORL __builtin_floorl + #define __BUILTIN_CEILF __builtin_ceilf + #define __BUILTIN_CEIL __builtin_ceill + #define __BUILTIN_CEILL __builtin_ceill + #define __BUILTIN_FREXPF __builtin_frexpf + #define __BUILTIN_FREXP __builtin_frexpl + #define __BUILTIN_FREXPL __builtin_frexpl + #define __BUILTIN_LDEXPF __builtin_ldexpf + #define __BUILTIN_LDEXP __builtin_ldexpl + #define __BUILTIN_LDEXPL __builtin_ldexpl + #define __BUILTIN_LROUNDF __builtin_lroundf + #define __BUILTIN_LROUND __builtin_lroundl + #define __BUILTIN_LROUNDL __builtin_lroundl + #define __BUILTIN_SQRTF __builtin_sqrtf + #define __BUILTIN_SQRT __builtin_sqrtl + #define __BUILTIN_SQRTL __builtin_sqrtl + #define __BUILTIN_CBRTF __builtin_cbrtf + #define __BUILTIN_CBRT __builtin_cbrtl + #define __BUILTIN_CBRTL __builtin_cbrtl + #define __BUILTIN_SINF __builtin_sinf + #define __BUILTIN_SIN __builtin_sinl + #define __BUILTIN_SINL __builtin_sinl + #define __BUILTIN_COSF __builtin_cosf + #define __BUILTIN_COS __builtin_cosl + #define __BUILTIN_COSL __builtin_cosl + #define __BUILTIN_TANF __builtin_tanf + #define __BUILTIN_TAN __builtin_tanl + #define __BUILTIN_TANL __builtin_tanl + #define __BUILTIN_ASINF __builtin_asinf + #define __BUILTIN_ASIN __builtin_asinl + #define __BUILTIN_ASINL __builtin_asinl + #define __BUILTIN_ACOSF __builtin_acosf + #define __BUILTIN_ACOS __builtin_acosl + #define __BUILTIN_ACOSL __builtin_acosl + #define __BUILTIN_ATANF __builtin_atanf + #define __BUILTIN_ATAN __builtin_atanl + #define __BUILTIN_ATANL __builtin_atanl + #define __BUILTIN_ATAN2F __builtin_atan2f + #define __BUILTIN_ATAN2 __builtin_atan2l + #define __BUILTIN_ATAN2L __builtin_atan2l + #define __BUILTIN_EXPF __builtin_expf + #define __BUILTIN_EXP __builtin_expl + #define __BUILTIN_EXPL __builtin_expl + #define __BUILTIN_POWF __builtin_powf + #define __BUILTIN_POW __builtin_powl + #define __BUILTIN_POWL __builtin_powl + #define __BUILTIN_LOGF __builtin_logf + #define __BUILTIN_LOG __builtin_logl + #define __BUILTIN_LOGL __builtin_logl + #define __BUILTIN_LOG10F __builtin_log10f + #define __BUILTIN_LOG10 __builtin_log10l + #define __BUILTIN_LOG10L __builtin_log10l + #define __BUILTIN_SINHF __builtin_sinhf + #define __BUILTIN_SINH __builtin_sinhl + #define __BUILTIN_SINHL __builtin_sinhl + #define __BUILTIN_COSHF __builtin_coshf + #define __BUILTIN_COSH __builtin_coshl + #define __BUILTIN_COSHL __builtin_coshl + #define __BUILTIN_TANHF __builtin_tanhf + #define __BUILTIN_TANH __builtin_tanhl + #define __BUILTIN_TANHL __builtin_tanhl #else #error Error: sizeof(double) is unknown or not standard for AVR. #endif extern "C" { - //int isfinitef(float x); - int isfinitel(long double x); - int ilogbf(float x); - int ilogb (double x); - int ilogbl(long double x); - float asinhf(float x); double asinh (double x); long double asinhl(long double x); @@ -233,6 +234,53 @@ double atanh (double x); long double atanhl(long double x); + int fpclassifyf(float x); + int fpclassify (double x); + + static inline int fpclassifyl(long double x) + { + #if defined(__GNUC__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" + #endif + + if((::__BUILTIN_ISNANL)(x) != 0) + { + return FP_NAN; + } + else if((::__BUILTIN_ISINFL)(x) != 0.0L) + { + return FP_INFINITE; + } + else if((::__BUILTIN_FABSL)(x) == 0.0L) + { + return FP_ZERO; + } + else + { + const bool + is_subnormal + { + ( + ((::__BUILTIN_FABSL)(x) > 0.0L) + && ((::__BUILTIN_FABSL)(x) < (std::numeric_limits::min)()) + ) + }; + + return (is_subnormal ? FP_SUBNORMAL : FP_NORMAL); + } + + #if defined(__GNUC__) + #pragma GCC diagnostic pop + #endif + } + + //int isfinitef(float x); + int isfinitel(long double x); + int ilogbf(float x); + int ilogb (double x); + int ilogbl(long double x); + float tgammaf(float x); double tgamma (double x); long double tgammal(long double x); @@ -244,102 +292,105 @@ namespace std { - inline bool isfinite(float x) { return ::isfinitef(x) == 1; } - inline bool isfinite(double x) { return ::isfinite (x) == 1; } - inline bool isfinite(long double x) { return ::isfinitel(x) == 1; } - inline int ilogb (float x) { return ::ilogbf (x); } - inline int ilogb (double x) { return ::ilogb (x); } - inline int ilogb (long double x) { return ::ilogbl (x); } - inline bool isnan (float x) { return __BUILTIN_ISNANF (x) == 1; } - inline bool isnan (double x) { return __BUILTIN_ISNAN (x) == 1; } - inline bool isnan (long double x) { return __BUILTIN_ISNANL (x) == 1; } - inline float fabs (float x) { return __BUILTIN_FABSF (x); } - inline double fabs (double x) { return __BUILTIN_FABS (x); } - inline long double fabs (long double x) { return __BUILTIN_FABSL (x); } - inline float fmod (float x, float y) { return __BUILTIN_FMODF (x, y); } - inline double fmod (double x, double y) { return __BUILTIN_FMOD (x, y); } - inline long double fmod (long double x, long double y) { return __BUILTIN_FMODL (x, y); } - inline float modf (float x, float* intptr) { return __BUILTIN_MODFF (x, intptr); } - inline double modf (double x, double* intptr) { return __BUILTIN_MODF (x, intptr); } - inline long double modf (long double x, long double* intptr) { return __BUILTIN_MODFL (x, intptr); } - inline float floor (float x) { return __BUILTIN_FLOORF(x); } - inline double floor (double x) { return __BUILTIN_FLOOR (x); } - inline long double floor (long double x) { return __BUILTIN_FLOORL(x); } - inline float ceil (float x) { return __BUILTIN_CEILF (x); } - inline double ceil (double x) { return __BUILTIN_CEIL (x); } - inline long double ceil (long double x) { return __BUILTIN_CEILL (x); } - inline float frexp (float x, int* p) { return __BUILTIN_FREXPF(x, p); } - inline double frexp (double x, int* p) { return __BUILTIN_FREXP (x, p); } - inline long double frexp (long double x, int* p) { return __BUILTIN_FREXPL(x, p); } - inline float ldexp (float x, int p) { return __BUILTIN_LDEXPF(x, p); } - inline double ldexp (double x, int p) { return __BUILTIN_LDEXP (x, p); } - inline long double ldexp (long double x, int p) { return __BUILTIN_LDEXPL(x, p); } - inline long lround (float x) { return __BUILTIN_LROUNDF(x); } - inline long lround (double x) { return __BUILTIN_LROUND (x); } - inline long lround (long double x) { return __BUILTIN_LROUNDL(x); } - inline float sqrt (float x) { return __BUILTIN_SQRTF (x); } - inline double sqrt (double x) { return __BUILTIN_SQRT (x); } - inline long double sqrt (long double x) { return __BUILTIN_SQRTL (x); } - inline float cbrt (float x) { return __BUILTIN_CBRTF (x); } - inline double cbrt (double x) { return __BUILTIN_CBRT (x); } - inline long double cbrt (long double x) { return __BUILTIN_CBRTL (x); } - inline float sin (float x) { return __BUILTIN_SINF (x); } - inline double sin (double x) { return __BUILTIN_SIN (x); } - inline long double sin (long double x) { return __BUILTIN_SINL (x); } - inline float cos (float x) { return __BUILTIN_COSF (x); } - inline double cos (double x) { return __BUILTIN_COS (x); } - inline long double cos (long double x) { return __BUILTIN_COSL (x); } - inline float tan (float x) { return __BUILTIN_TANF (x); } - inline double tan (double x) { return __BUILTIN_TAN (x); } - inline long double tan (long double x) { return __BUILTIN_TANL (x); } - inline float asin (float x) { return __BUILTIN_ASINF (x); } - inline double asin (double x) { return __BUILTIN_ASIN (x); } - inline long double asin (long double x) { return __BUILTIN_ASINL (x); } - inline float acos (float x) { return __BUILTIN_ACOSF (x); } - inline double acos (double x) { return __BUILTIN_ACOS (x); } - inline long double acos (long double x) { return __BUILTIN_ACOSL (x); } - inline float atan (float x) { return __BUILTIN_ATANF (x); } - inline double atan (double x) { return __BUILTIN_ATAN (x); } - inline long double atan (long double x) { return __BUILTIN_ATANL (x); } - inline float atan2 (float y, float x) { return __BUILTIN_ATAN2F(y, x); } - inline double atan2 (double y, double x) { return __BUILTIN_ATAN2 (y, x); } - inline long double atan2 (long double y, long double x) { return __BUILTIN_ATAN2L(y, x); } - inline float exp (float x) { return __BUILTIN_EXPF (x); } - inline double exp (double x) { return __BUILTIN_EXP (x); } - inline long double exp (long double x) { return __BUILTIN_EXPL (x); } - inline float pow (float x, float a) { return __BUILTIN_POWF (x, a); } - inline double pow (double x, double a) { return __BUILTIN_POW (x, a); } - inline long double pow (long double x, long double a) { return __BUILTIN_POWL (x, a); } - inline float log (float x) { return __BUILTIN_LOGF (x); } - inline double log (double x) { return __BUILTIN_LOG (x); } - inline long double log (long double x) { return __BUILTIN_LOGL (x); } - inline float log10 (float x) { return __BUILTIN_LOG10F(x); } - inline double log10 (double x) { return __BUILTIN_LOG10 (x); } - inline long double log10 (long double x) { return __BUILTIN_LOG10L(x); } - inline float sinh (float x) { return __BUILTIN_SINHF (x); } - inline double sinh (double x) { return __BUILTIN_SINH (x); } - inline long double sinh (long double x) { return __BUILTIN_SINHL (x); } - inline float cosh (float x) { return __BUILTIN_COSHF (x); } - inline double cosh (double x) { return __BUILTIN_COSH (x); } - inline long double cosh (long double x) { return __BUILTIN_COSHL (x); } - inline float tanh (float x) { return __BUILTIN_TANHF (x); } - inline double tanh (double x) { return __BUILTIN_TANH (x); } - inline long double tanh (long double x) { return __BUILTIN_TANHL (x); } - inline float asinh (float x) { return ::asinhf(x); } - inline double asinh (double x) { return ::asinh (x); } - inline long double asinh (long double x) { return ::asinhl(x); } - inline float acosh (float x) { return ::acoshf(x); } - inline double acosh (double x) { return ::acosh (x); } - inline long double acosh (long double x) { return ::acoshl(x); } - inline float atanh (float x) { return ::asinhf(x); } - inline double atanh (double x) { return ::asinh (x); } - inline long double atanh (long double x) { return ::asinhl(x); } - inline float tgamma (float x) { return ::tgammaf(x); } - inline double tgamma (double x) { return ::tgamma (x); } - inline long double tgamma (long double x) { return ::tgammal(x); } - inline float lgamma (float x) { return ::lgammaf(x); } - inline double lgamma (double x) { return ::lgamma (x); } - inline long double lgamma (long double x) { return ::lgammal(x); } + inline bool isfinite (float x) { return ::isfinitef(x) == 1; } + inline bool isfinite (double x) { return ::isfinite (x) == 1; } + inline bool isfinite (long double x) { return ::isfinitel(x) == 1; } + inline int ilogb (float x) { return ::ilogbf (x); } + inline int ilogb (double x) { return ::ilogb (x); } + inline int ilogb (long double x) { return ::ilogbl (x); } + inline int fpclassify(float x) { return ::fpclassifyf(x); } + inline int fpclassify(double x) { return ::fpclassify (x); } + inline int fpclassify(long double x) { return ::fpclassifyl(x); } + inline bool isnan (float x) { return __BUILTIN_ISNANF (x) == 1; } + inline bool isnan (double x) { return __BUILTIN_ISNAN (x) == 1; } + inline bool isnan (long double x) { return __BUILTIN_ISNANL (x) == 1; } + inline float fabs (float x) { return __BUILTIN_FABSF (x); } + inline double fabs (double x) { return __BUILTIN_FABS (x); } + inline long double fabs (long double x) { return __BUILTIN_FABSL (x); } + inline float fmod (float x, float y) { return __BUILTIN_FMODF (x, y); } + inline double fmod (double x, double y) { return __BUILTIN_FMOD (x, y); } + inline long double fmod (long double x, long double y) { return __BUILTIN_FMODL (x, y); } + inline float modf (float x, float* intptr) { return __BUILTIN_MODFF (x, intptr); } + inline double modf (double x, double* intptr) { return __BUILTIN_MODF (x, intptr); } + inline long double modf (long double x, long double* intptr) { return __BUILTIN_MODFL (x, intptr); } + inline float floor (float x) { return __BUILTIN_FLOORF(x); } + inline double floor (double x) { return __BUILTIN_FLOOR (x); } + inline long double floor (long double x) { return __BUILTIN_FLOORL(x); } + inline float ceil (float x) { return __BUILTIN_CEILF (x); } + inline double ceil (double x) { return __BUILTIN_CEIL (x); } + inline long double ceil (long double x) { return __BUILTIN_CEILL (x); } + inline float frexp (float x, int* p) { return __BUILTIN_FREXPF(x, p); } + inline double frexp (double x, int* p) { return __BUILTIN_FREXP (x, p); } + inline long double frexp (long double x, int* p) { return __BUILTIN_FREXPL(x, p); } + inline float ldexp (float x, int p) { return __BUILTIN_LDEXPF(x, p); } + inline double ldexp (double x, int p) { return __BUILTIN_LDEXP (x, p); } + inline long double ldexp (long double x, int p) { return __BUILTIN_LDEXPL(x, p); } + inline long lround (float x) { return __BUILTIN_LROUNDF(x); } + inline long lround (double x) { return __BUILTIN_LROUND (x); } + inline long lround (long double x) { return __BUILTIN_LROUNDL(x); } + inline float sqrt (float x) { return __BUILTIN_SQRTF (x); } + inline double sqrt (double x) { return __BUILTIN_SQRT (x); } + inline long double sqrt (long double x) { return __BUILTIN_SQRTL (x); } + inline float cbrt (float x) { return __BUILTIN_CBRTF (x); } + inline double cbrt (double x) { return __BUILTIN_CBRT (x); } + inline long double cbrt (long double x) { return __BUILTIN_CBRTL (x); } + inline float sin (float x) { return __BUILTIN_SINF (x); } + inline double sin (double x) { return __BUILTIN_SIN (x); } + inline long double sin (long double x) { return __BUILTIN_SINL (x); } + inline float cos (float x) { return __BUILTIN_COSF (x); } + inline double cos (double x) { return __BUILTIN_COS (x); } + inline long double cos (long double x) { return __BUILTIN_COSL (x); } + inline float tan (float x) { return __BUILTIN_TANF (x); } + inline double tan (double x) { return __BUILTIN_TAN (x); } + inline long double tan (long double x) { return __BUILTIN_TANL (x); } + inline float asin (float x) { return __BUILTIN_ASINF (x); } + inline double asin (double x) { return __BUILTIN_ASIN (x); } + inline long double asin (long double x) { return __BUILTIN_ASINL (x); } + inline float acos (float x) { return __BUILTIN_ACOSF (x); } + inline double acos (double x) { return __BUILTIN_ACOS (x); } + inline long double acos (long double x) { return __BUILTIN_ACOSL (x); } + inline float atan (float x) { return __BUILTIN_ATANF (x); } + inline double atan (double x) { return __BUILTIN_ATAN (x); } + inline long double atan (long double x) { return __BUILTIN_ATANL (x); } + inline float atan2 (float y, float x) { return __BUILTIN_ATAN2F(y, x); } + inline double atan2 (double y, double x) { return __BUILTIN_ATAN2 (y, x); } + inline long double atan2 (long double y, long double x) { return __BUILTIN_ATAN2L(y, x); } + inline float exp (float x) { return __BUILTIN_EXPF (x); } + inline double exp (double x) { return __BUILTIN_EXP (x); } + inline long double exp (long double x) { return __BUILTIN_EXPL (x); } + inline float pow (float x, float a) { return __BUILTIN_POWF (x, a); } + inline double pow (double x, double a) { return __BUILTIN_POW (x, a); } + inline long double pow (long double x, long double a) { return __BUILTIN_POWL (x, a); } + inline float log (float x) { return __BUILTIN_LOGF (x); } + inline double log (double x) { return __BUILTIN_LOG (x); } + inline long double log (long double x) { return __BUILTIN_LOGL (x); } + inline float log10 (float x) { return __BUILTIN_LOG10F(x); } + inline double log10 (double x) { return __BUILTIN_LOG10 (x); } + inline long double log10 (long double x) { return __BUILTIN_LOG10L(x); } + inline float sinh (float x) { return __BUILTIN_SINHF (x); } + inline double sinh (double x) { return __BUILTIN_SINH (x); } + inline long double sinh (long double x) { return __BUILTIN_SINHL (x); } + inline float cosh (float x) { return __BUILTIN_COSHF (x); } + inline double cosh (double x) { return __BUILTIN_COSH (x); } + inline long double cosh (long double x) { return __BUILTIN_COSHL (x); } + inline float tanh (float x) { return __BUILTIN_TANHF (x); } + inline double tanh (double x) { return __BUILTIN_TANH (x); } + inline long double tanh (long double x) { return __BUILTIN_TANHL (x); } + inline float asinh (float x) { return ::asinhf(x); } + inline double asinh (double x) { return ::asinh (x); } + inline long double asinh (long double x) { return ::asinhl(x); } + inline float acosh (float x) { return ::acoshf(x); } + inline double acosh (double x) { return ::acosh (x); } + inline long double acosh (long double x) { return ::acoshl(x); } + inline float atanh (float x) { return ::asinhf(x); } + inline double atanh (double x) { return ::asinh (x); } + inline long double atanh (long double x) { return ::asinhl(x); } + inline float tgamma (float x) { return ::tgammaf(x); } + inline double tgamma (double x) { return ::tgamma (x); } + inline long double tgamma (long double x) { return ::tgammal(x); } + inline float lgamma (float x) { return ::lgammaf(x); } + inline double lgamma (double x) { return ::lgamma (x); } + inline long double lgamma (long double x) { return ::lgammal(x); } } #else @@ -349,70 +400,72 @@ { #endif // These are (most of) the functions from having C-linkage. - int isfinitef(float); - int isfinitel(long double); - int ilogbf (float); - int ilogbl (long double); - int isnanf (float); - int isnanl (long double); - float fabsf (float x); - long double fabsl (long double x); - float fmodf (float x, float y); - long double fmodl (long double x, long double y); - float modff (float x, float* intptr); - long double modfl (long double x, long double* intptr); - float floorf (float x); - long double floorl (long double x); - float ceilf (float x); - long double ceill (long double x); - float frexpf (float x, int* p); - long double frexpl (long double x, int* p); - float ldexpf (float x, int p); - long double ldexpl (long double x, int p); - long lroundf (float x); - long lroundl (long double x); - float sqrtf (float x); - long double sqrtl (long double x); - float cbrtf (float x); - long double cbrtl (long double x); - float sinf (float x); - long double sinl (long double x); - float cosf (float x); - long double cosl (long double x); - float tanf (float x); - long double tanl (long double x); - float asinf (float x); - long double asinl (long double x); - float acosf (float x); - long double acosl (long double x); - float atanf (float x); - long double atanl (long double x); - float atan2f (float y, float x); - long double atan2l (long double y, long double x); - float expf (float x); - long double expl (long double x); - float powf (float x, float a); - long double powl (long double x, long double a); - float logf (float x); - long double logl (long double x); - float log10f (float x); - long double log10l (long double x); - float sinhf (float x); - long double sinhl (long double x); - float coshf (float x); - long double coshl (long double x); - float tanhf (float x); - long double tanhl (long double x); - float asinhf (float x); - long double asinhl (long double x); - float acoshf (float x); - long double acoshl (long double x); - float atanhf (float x); - long double atanhl (long double x); - float tgammaf (float x); - long double tgammal (long double x); - float lgammaf (float x); - long double lgammal (long double x); + int isfinitef (float); + int isfinitel (long double); + int ilogbf (float); + int ilogbl (long double); + int isnanf (float); + int isnanl (long double); + float fabsf (float x); + long double fabsl (long double x); + float fmodf (float x, float y); + long double fmodl (long double x, long double y); + float modff (float x, float* intptr); + long double modfl (long double x, long double* intptr); + float floorf (float x); + long double floorl (long double x); + float ceilf (float x); + long double ceill (long double x); + float frexpf (float x, int* p); + long double frexpl (long double x, int* p); + int fpclassifyf(float x); + int fpclassifyl(long double x); + float ldexpf (float x, int p); + long double ldexpl (long double x, int p); + long lroundf (float x); + long lroundl (long double x); + float sqrtf (float x); + long double sqrtl (long double x); + float cbrtf (float x); + long double cbrtl (long double x); + float sinf (float x); + long double sinl (long double x); + float cosf (float x); + long double cosl (long double x); + float tanf (float x); + long double tanl (long double x); + float asinf (float x); + long double asinl (long double x); + float acosf (float x); + long double acosl (long double x); + float atanf (float x); + long double atanl (long double x); + float atan2f (float y, float x); + long double atan2l (long double y, long double x); + float expf (float x); + long double expl (long double x); + float powf (float x, float a); + long double powl (long double x, long double a); + float logf (float x); + long double logl (long double x); + float log10f (float x); + long double log10l (long double x); + float sinhf (float x); + long double sinhl (long double x); + float coshf (float x); + long double coshl (long double x); + float tanhf (float x); + long double tanhl (long double x); + float asinhf (float x); + long double asinhl (long double x); + float acoshf (float x); + long double acoshl (long double x); + float atanhf (float x); + long double atanhl (long double x); + float tgammaf (float x); + long double tgammal (long double x); + float lgammaf (float x); + long double lgammal (long double x); #if defined(__cplusplus) } #endif @@ -421,223 +474,197 @@ extern "C++" { #endif - inline bool isfinite(float x) { return (::isfinitef(x) == 1); } - inline bool isfinite(double x) { return (::isfinite (x) == 1); } - inline bool isfinite(long double x) { return (::isfinitel(x) == 1); } - inline int ilogb (float x) { return ::ilogbf(x); } - inline int ilogb (double x) { return ::ilogb (x); } - inline int ilogb (long double x) { return ::ilogbl(x); } + inline bool isfinite (float x) { return (::isfinitef(x) == 1); } + inline bool isfinite (double x) { return (::isfinite (x) == 1); } + inline bool isfinite (long double x) { return (::isfinitel(x) == 1); } + inline int ilogb (float x) { return ::ilogbf(x); } + inline int ilogb (double x) { return ::ilogb (x); } + inline int ilogb (long double x) { return ::ilogbl(x); } + inline int fpclassify(float x) { return ::fpclassifyf(x); } + inline int fpclassify(double x) { return ::fpclassify (x); } + inline int fpclassify(long double x) { return ::fpclassifyl(x); } #if (defined(__GNUC__) && !defined(__clang__)) - inline bool isnan (float x) { return __builtin_isnanf(x); } - inline bool isnan (double x) { return __builtin_isnan (x); } - inline bool isnan (long double x) { return __builtin_isnanl(x); } - inline float abs (float x) { return __builtin_fabsf (x); } - inline double abs (double x) { return __builtin_fabs (x); } - inline long double abs (long double x) { return __builtin_fabsl (x); } - inline float fabs (float x) { return __builtin_fabsf (x); } - inline double fabs (double x) { return __builtin_fabs (x); } - inline long double fabs (long double x) { return __builtin_fabsl (x); } - inline float fmod (float x, float y) { return __builtin_fmodf (x, y); } - inline double fmod (double x, double y) { return __builtin_fmod (x, y); } - inline long double fmod (long double x, long double y) { return __builtin_fmodl (x, y); } - inline float modf (float x, float* p) { return __builtin_modff (x, p); } - inline double modf (double x, double* p) { return __builtin_modf (x, p); } - inline long double modf (long double x, long double* p) { return __builtin_modfl (x, p); } - inline float floor (float x) { return __builtin_floorf(x); } - inline double floor (double x) { return __builtin_floor (x); } - inline long double floor (long double x) { return __builtin_floorl(x); } - inline float ceil (float x) { return __builtin_ceilf (x); } - inline double ceil (double x) { return __builtin_ceil (x); } - inline long double ceil (long double x) { return __builtin_ceill (x); } - inline float frexp (float x, int* p) { return __builtin_frexpf(x, p); } - inline double frexp (double x, int* p) { return __builtin_frexp (x, p); } - inline long double frexp (long double x, int* p) { return __builtin_frexpl(x, p); } - inline float ldexp (float x, int p) { return __builtin_ldexpf(x, p); } - inline double ldexp (double x, int p) { return __builtin_ldexp (x, p); } - inline long double ldexp (long double x, int p) { return __builtin_ldexpl(x, p); } - inline long lround (float x) { return __builtin_lroundf(x); } - inline long lround (double x) { return __builtin_lround (x); } - inline long lround (long double x) { return __builtin_lroundl(x); } - inline float sqrt (float x) { return __builtin_sqrtf (x); } - inline double sqrt (double x) { return __builtin_sqrt (x); } - inline long double sqrt (long double x) { return __builtin_sqrtl (x); } - inline float cbrt (float x) { return __builtin_cbrtf (x); } - inline double cbrt (double x) { return __builtin_cbrt (x); } - inline long double cbrt (long double x) { return __builtin_cbrtl (x); } - inline float sin (float x) { return __builtin_sinf (x); } - inline double sin (double x) { return __builtin_sin (x); } - inline long double sin (long double x) { return __builtin_sinl (x); } - inline float cos (float x) { return __builtin_cosf (x); } - inline double cos (double x) { return __builtin_cos (x); } - inline long double cos (long double x) { return __builtin_cosl (x); } - inline float tan (float x) { return __builtin_tanf (x); } - inline double tan (double x) { return __builtin_tan (x); } - inline long double tan (long double x) { return __builtin_tanl (x); } - inline float asin (float x) { return __builtin_asinf (x); } - inline double asin (double x) { return __builtin_asin (x); } - inline long double asin (long double x) { return __builtin_asinl (x); } - inline float acos (float x) { return __builtin_acosf (x); } - inline double acos (double x) { return __builtin_acos (x); } - inline long double acos (long double x) { return __builtin_acosl (x); } - inline float atan (float x) { return __builtin_atanf (x); } - inline double atan (double x) { return __builtin_atan (x); } - inline long double atan (long double x) { return __builtin_atanl (x); } - inline float atan2 (float y, float x) { return __builtin_atan2f(y, x); } - inline double atan2 (double y, double x) { return __builtin_atan2 (y, x); } - inline long double atan2 (long double y, long double x) { return __builtin_atan2l(y, x); } - inline float exp (float x) { return __builtin_expf (x); } - inline double exp (double x) { return __builtin_exp (x); } - inline long double exp (long double x) { return __builtin_expl (x); } - inline float pow (float x, float a) { return __builtin_powf (x, a); } - inline double pow (double x, double a) { return __builtin_pow (x, a); } - inline long double pow (long double x, long double a) { return __builtin_powl (x, a); } - inline float log (float x) { return __builtin_logf (x); } - inline double log (double x) { return __builtin_log (x); } - inline long double log (long double x) { return __builtin_logl (x); } - inline float log10 (float x) { return __builtin_log10f(x); } - inline double log10 (double x) { return __builtin_log10 (x); } - inline long double log10 (long double x) { return __builtin_log10l(x); } - inline float sinh (float x) { return __builtin_sinhf (x); } - inline double sinh (double x) { return __builtin_sinh (x); } - inline long double sinh (long double x) { return __builtin_sinhl (x); } - inline float cosh (float x) { return __builtin_coshf (x); } - inline double cosh (double x) { return __builtin_cosh (x); } - inline long double cosh (long double x) { return __builtin_coshl (x); } - inline float tanh (float x) { return __builtin_tanhf (x); } - inline double tanh (double x) { return __builtin_tanh (x); } - inline long double tanh (long double x) { return __builtin_tanhl (x); } + inline bool isnan (float x) { return __builtin_isnanf(x); } + inline bool isnan (double x) { return __builtin_isnan (x); } + inline bool isnan (long double x) { return __builtin_isnanl(x); } + inline float abs (float x) { return __builtin_fabsf (x); } + inline double abs (double x) { return __builtin_fabs (x); } + inline long double abs (long double x) { return __builtin_fabsl (x); } + inline float fabs (float x) { return __builtin_fabsf (x); } + inline double fabs (double x) { return __builtin_fabs (x); } + inline long double fabs (long double x) { return __builtin_fabsl (x); } + inline float fmod (float x, float y) { return __builtin_fmodf (x, y); } + inline double fmod (double x, double y) { return __builtin_fmod (x, y); } + inline long double fmod (long double x, long double y) { return __builtin_fmodl (x, y); } + inline float modf (float x, float* p) { return __builtin_modff (x, p); } + inline double modf (double x, double* p) { return __builtin_modf (x, p); } + inline long double modf (long double x, long double* p) { return __builtin_modfl (x, p); } + inline float floor (float x) { return __builtin_floorf(x); } + inline double floor (double x) { return __builtin_floor (x); } + inline long double floor (long double x) { return __builtin_floorl(x); } + inline float ceil (float x) { return __builtin_ceilf (x); } + inline double ceil (double x) { return __builtin_ceil (x); } + inline long double ceil (long double x) { return __builtin_ceill (x); } + inline float frexp (float x, int* p) { return __builtin_frexpf(x, p); } + inline double frexp (double x, int* p) { return __builtin_frexp (x, p); } + inline long double frexp (long double x, int* p) { return __builtin_frexpl(x, p); } + inline float ldexp (float x, int p) { return __builtin_ldexpf(x, p); } + inline double ldexp (double x, int p) { return __builtin_ldexp (x, p); } + inline long double ldexp (long double x, int p) { return __builtin_ldexpl(x, p); } + inline long lround (float x) { return __builtin_lroundf(x); } + inline long lround (double x) { return __builtin_lround (x); } + inline long lround (long double x) { return __builtin_lroundl(x); } + inline float sqrt (float x) { return __builtin_sqrtf (x); } + inline double sqrt (double x) { return __builtin_sqrt (x); } + inline long double sqrt (long double x) { return __builtin_sqrtl (x); } + inline float cbrt (float x) { return __builtin_cbrtf (x); } + inline double cbrt (double x) { return __builtin_cbrt (x); } + inline long double cbrt (long double x) { return __builtin_cbrtl (x); } + inline float sin (float x) { return __builtin_sinf (x); } + inline double sin (double x) { return __builtin_sin (x); } + inline long double sin (long double x) { return __builtin_sinl (x); } + inline float cos (float x) { return __builtin_cosf (x); } + inline double cos (double x) { return __builtin_cos (x); } + inline long double cos (long double x) { return __builtin_cosl (x); } + inline float tan (float x) { return __builtin_tanf (x); } + inline double tan (double x) { return __builtin_tan (x); } + inline long double tan (long double x) { return __builtin_tanl (x); } + inline float asin (float x) { return __builtin_asinf (x); } + inline double asin (double x) { return __builtin_asin (x); } + inline long double asin (long double x) { return __builtin_asinl (x); } + inline float acos (float x) { return __builtin_acosf (x); } + inline double acos (double x) { return __builtin_acos (x); } + inline long double acos (long double x) { return __builtin_acosl (x); } + inline float atan (float x) { return __builtin_atanf (x); } + inline double atan (double x) { return __builtin_atan (x); } + inline long double atan (long double x) { return __builtin_atanl (x); } + inline float atan2 (float y, float x) { return __builtin_atan2f(y, x); } + inline double atan2 (double y, double x) { return __builtin_atan2 (y, x); } + inline long double atan2 (long double y, long double x) { return __builtin_atan2l(y, x); } + inline float exp (float x) { return __builtin_expf (x); } + inline double exp (double x) { return __builtin_exp (x); } + inline long double exp (long double x) { return __builtin_expl (x); } + inline float pow (float x, float a) { return __builtin_powf (x, a); } + inline double pow (double x, double a) { return __builtin_pow (x, a); } + inline long double pow (long double x, long double a) { return __builtin_powl (x, a); } + inline float log (float x) { return __builtin_logf (x); } + inline double log (double x) { return __builtin_log (x); } + inline long double log (long double x) { return __builtin_logl (x); } + inline float log10 (float x) { return __builtin_log10f(x); } + inline double log10 (double x) { return __builtin_log10 (x); } + inline long double log10 (long double x) { return __builtin_log10l(x); } + inline float sinh (float x) { return __builtin_sinhf (x); } + inline double sinh (double x) { return __builtin_sinh (x); } + inline long double sinh (long double x) { return __builtin_sinhl (x); } + inline float cosh (float x) { return __builtin_coshf (x); } + inline double cosh (double x) { return __builtin_cosh (x); } + inline long double cosh (long double x) { return __builtin_coshl (x); } + inline float tanh (float x) { return __builtin_tanhf (x); } + inline double tanh (double x) { return __builtin_tanh (x); } + inline long double tanh (long double x) { return __builtin_tanhl (x); } #else - inline bool isnan (float x) { return ::isnanf(x); } - bool isnan (double x); - inline bool isnan (long double x) { return ::isnanl(x); } - inline float abs (float x) { return ::fabsf (x); } - extern "C" - double abs (double x); - inline long double abs (long double x) { return ::fabsl (x); } - inline float fabs (float x) { return ::fabsf (x); } - extern "C" - double fabs (double x); - inline long double fabs (long double x) { return ::fabsl (x); } - inline float fmod (float x, float y) { return ::fmodf(x, y); } - extern "C" - double fmod (double x, double y); - inline long double fmod (long double x, long double y) { return ::fmodl(x, y); } - inline float modf (float x, float* p) { return ::modff (x, p); } - extern "C" - double modf (double x, double* p); - inline long double modf (long double x, long double* p) { return ::modfl (x, p); } - inline float floor (float x) { return ::floorf(x); } - extern "C" - double floor (double x); - inline long double floor (long double x) { return ::floorl(x); } - inline float ceil (float x) { return ::ceilf (x); } - extern "C" - double ceil (double x); - inline long double ceil (long double x) { return ::ceill (x); } - inline float frexp (float x, int* p) { return ::frexpf(x, p); } - extern "C" - double frexp (double x, int* p); - inline long double frexp (long double x, int* p) { return ::frexpl(x, p); } - inline float ldexp (float x, int p) { return ::ldexpf(x, p); } - extern "C" - double ldexp (double x, int p); - inline long double ldexp (long double x, int p) { return ::ldexpl (x, p); } - inline long lround (float x) { return ::lroundf(x); } - extern "C" - long lround (double x); - inline long lround (long double x) { return ::lroundl(x); } - inline float sqrt (float x) { return ::sqrtf (x); } - extern "C" - double sqrt (double x); - inline long double sqrt (long double x) { return ::sqrtl (x); } - inline float cbrt (float x) { return ::cbrtf (x); } - extern "C" - double cbrt (double x); - inline long double cbrt (long double x) { return ::cbrtl (x); } - inline float sin (float x) { return ::sinf (x); } - extern "C" - double sin (double x); - inline long double sin (long double x) { return ::sinl (x); } - inline float cos (float x) { return ::cosf (x); } - extern "C" - double cos (double x); - inline long double cos (long double x) { return ::cosl (x); } - inline float tan (float x) { return ::tanf (x); } - extern "C" - double tan (double x); - inline long double tan (long double x) { return ::tanl (x); } - inline float asin (float x) { return ::asinf (x); } - extern "C" - double asin (double x); - inline long double asin (long double x) { return ::asinl (x); } - inline float acos (float x) { return ::acosf (x); } - extern "C" - double acos (double x); - inline long double acos (long double x) { return ::acosl (x); } - inline float atan (float x) { return ::atanf (x); } - extern "C" - double atan (double x); - inline long double atan (long double x) { return ::atanl (x); } - inline float atan2 (float y, float x) { return ::atan2f(y, x); } - extern "C" - double atan2 (double y, double x); - inline long double atan2 (long double y, long double x) { return ::atan2l(y, x); } - inline float exp (float x) { return ::expf (x); } - extern "C" - double exp (double x); - inline long double exp (long double x) { return ::expl (x); } - inline float pow (float x, float a) { return ::powf (x, a); } - extern "C" - double pow (double x, double a); - inline long double pow (long double x, long double a) { return ::powl (x, a); } - inline float log (float x) { return ::logf (x); } - extern "C" - double log (double x); - inline long double log (long double x) { return ::logl (x); } - inline float log10 (float x) { return ::log10f(x); } - extern "C" - double log10 (double x); - inline long double log10 (long double x) { return ::log10l(x); } - inline float sinh (float x) { return ::sinhf (x); } - extern "C" - double sinh (double x); - inline long double sinh (long double x) { return ::sinhl (x); } - inline float cosh (float x) { return ::coshf (x); } - extern "C" - double cosh (double x); - inline long double cosh (long double x) { return ::coshl (x); } - inline float tanh (float x) { return ::tanhf (x); } - extern "C" - double tanh (double x); - inline long double tanh (long double x) { return ::tanhl (x); } + inline bool isnan (float x) { return ::isnanf(x); } + bool isnan (double x); + inline bool isnan (long double x) { return ::isnanl(x); } + inline float abs (float x) { return ::fabsf (x); } + extern "C" double abs (double x); + inline long double abs (long double x) { return ::fabsl (x); } + inline float fabs (float x) { return ::fabsf (x); } + extern "C" double fabs (double x); + inline long double fabs (long double x) { return ::fabsl (x); } + inline float fmod (float x, float y) { return ::fmodf(x, y); } + extern "C" double fmod (double x, double y); + inline long double fmod (long double x, long double y) { return ::fmodl(x, y); } + inline float modf (float x, float* p) { return ::modff (x, p); } + extern "C" double modf (double x, double* p); + inline long double modf (long double x, long double* p) { return ::modfl (x, p); } + inline float floor (float x) { return ::floorf(x); } + extern "C" double floor (double x); + inline long double floor (long double x) { return ::floorl(x); } + inline float ceil (float x) { return ::ceilf (x); } + extern "C" double ceil (double x); + inline long double ceil (long double x) { return ::ceill (x); } + inline float frexp (float x, int* p) { return ::frexpf(x, p); } + extern "C" double frexp (double x, int* p); + inline long double frexp (long double x, int* p) { return ::frexpl(x, p); } + inline int fpclassify(float x) { return ::fpclassifyf (x); } + extern "C" int fpclassify(double x); + inline int fpclassify(long double x) { return ::fpclassifyl (x); } + inline float ldexp (float x, int p) { return ::ldexpf(x, p); } + extern "C" double ldexp (double x, int p); + inline long double ldexp (long double x, int p) { return ::ldexpl (x, p); } + inline long lround (float x) { return ::lroundf(x); } + extern "C" long lround (double x); + inline long lround (long double x) { return ::lroundl(x); } + inline float sqrt (float x) { return ::sqrtf (x); } + extern "C" double sqrt (double x); + inline long double sqrt (long double x) { return ::sqrtl (x); } + inline float cbrt (float x) { return ::cbrtf (x); } + extern "C" double cbrt (double x); + inline long double cbrt (long double x) { return ::cbrtl (x); } + inline float sin (float x) { return ::sinf (x); } + extern "C" double sin (double x); + inline long double sin (long double x) { return ::sinl (x); } + inline float cos (float x) { return ::cosf (x); } + extern "C" double cos (double x); + inline long double cos (long double x) { return ::cosl (x); } + inline float tan (float x) { return ::tanf (x); } + extern "C" double tan (double x); + inline long double tan (long double x) { return ::tanl (x); } + inline float asin (float x) { return ::asinf (x); } + extern "C" double asin (double x); + inline long double asin (long double x) { return ::asinl (x); } + inline float acos (float x) { return ::acosf (x); } + extern "C" double acos (double x); + inline long double acos (long double x) { return ::acosl (x); } + inline float atan (float x) { return ::atanf (x); } + extern "C" double atan (double x); + inline long double atan (long double x) { return ::atanl (x); } + inline float atan2 (float y, float x) { return ::atan2f(y, x); } + extern "C" double atan2 (double y, double x); + inline long double atan2 (long double y, long double x) { return ::atan2l(y, x); } + inline float exp (float x) { return ::expf (x); } + extern "C" double exp (double x); + inline long double exp (long double x) { return ::expl (x); } + inline float pow (float x, float a) { return ::powf (x, a); } + extern "C" double pow (double x, double a); + inline long double pow (long double x, long double a) { return ::powl (x, a); } + inline float log (float x) { return ::logf (x); } + extern "C" double log (double x); + inline long double log (long double x) { return ::logl (x); } + inline float log10 (float x) { return ::log10f(x); } + extern "C" double log10 (double x); + inline long double log10 (long double x) { return ::log10l(x); } + inline float sinh (float x) { return ::sinhf (x); } + extern "C" double sinh (double x); + inline long double sinh (long double x) { return ::sinhl (x); } + inline float cosh (float x) { return ::coshf (x); } + extern "C" double cosh (double x); + inline long double cosh (long double x) { return ::coshl (x); } + inline float tanh (float x) { return ::tanhf (x); } + extern "C" double tanh (double x); + inline long double tanh (long double x) { return ::tanhl (x); } #endif - inline float asinh (float x) { return ::asinhf(x); } - extern "C" - double asinh (double x); - inline long double asinh (long double x) { return ::asinhl(x); } - inline float acosh (float x) { return ::acoshf(x); } - extern "C" - double acosh (double x); - inline long double acosh (long double x) { return ::acoshl(x); } - inline float atanh (float x) { return ::atanhf(x); } - extern "C" - double atanh (double x); - inline long double atanh (long double x) { return ::atanhl(x); } - inline float tgamma (float x) { return ::tgammaf(x); } - extern "C" - double tgamma (double x); - inline long double tgamma (long double x) { return ::tgammal(x); } - inline float lgamma (float x) { return ::lgammaf(x); } - extern "C" - double lgamma (double x); - inline long double lgamma (long double x) { return ::lgammal(x); } + inline float asinh (float x) { return ::asinhf(x); } + extern "C" double asinh (double x); + inline long double asinh (long double x) { return ::asinhl(x); } + inline float acosh (float x) { return ::acoshf(x); } + extern "C" double acosh (double x); + inline long double acosh (long double x) { return ::acoshl(x); } + inline float atanh (float x) { return ::atanhf(x); } + extern "C" double atanh (double x); + inline long double atanh (long double x) { return ::atanhl(x); } + inline float tgamma (float x) { return ::tgammaf(x); } + extern "C" double tgamma (double x); + inline long double tgamma (long double x) { return ::tgammal(x); } + inline float lgamma (float x) { return ::lgammaf(x); } + extern "C" double lgamma (double x); + inline long double lgamma (long double x) { return ::lgammal(x); } #if __cplusplus > 201703L - inline float lerp (float a, float b, float t) - { return a + (t * (b - a)); } - inline double lerp (double a, double b, double t) - { return a + (t * (b - a)); } - inline long double lerp (long double a, long double b, long double t) - { return a + (t * (b - a)); } + inline float lerp (float a, float b, float t) { return a + (t * (b - a)); } + inline double lerp (double a, double b, double t) { return a + (t * (b - a)); } + inline long double lerp (long double a, long double b, long double t) + { return a + (t * (b - a)); } #endif #if defined(__cplusplus) } @@ -651,6 +678,7 @@ using ::abs; using ::fabs; using ::fmod; + using ::fpclassify; using ::modf; using ::floor; using ::ceil; @@ -682,4 +710,20 @@ #endif + #if !defined(FP_INFINITE) + #define FP_INFINITE 1 + #endif + #if !defined(FP_NAN) + #define FP_NAN 2 + #endif + #if !defined(FP_NORMAL) + #define FP_NORMAL (-1) + #endif + #if !defined(FP_SUBNORMAL) + #define FP_SUBNORMAL (-2) + #endif + #if !defined(FP_ZERO) + #define FP_ZERO 0 + #endif + #endif // CMATH_2010_02_23_ From f92da81db4bc1204ddeb285851a3c2bb5f3a32bf Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 15:55:23 +0200 Subject: [PATCH 2/7] Fix fixed-point and default 64-bit double AVR --- ref_app/src/math/fixed_point/fixed_point.h | 15 ++++++++------- .../micros/atmega2560/make/atmega2560_flags.gmk | 4 ++-- .../micros/atmega4809/make/atmega4809_flags.gmk | 2 +- ref_app/target/micros/avr/make/avr_flags.gmk | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ref_app/src/math/fixed_point/fixed_point.h b/ref_app/src/math/fixed_point/fixed_point.h index 9f8ade580..b3bf4feec 100644 --- a/ref_app/src/math/fixed_point/fixed_point.h +++ b/ref_app/src/math/fixed_point/fixed_point.h @@ -1,15 +1,19 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2018. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef FIXED_POINT_2011_02_22_H_ - #define FIXED_POINT_2011_02_22_H_ +#ifndef FIXED_POINT_2011_02_22_H + #define FIXED_POINT_2011_02_22_H #define FIXED_POINT_DISABLE_IOSTREAM + #include + #include + + #include #include #include #include @@ -19,9 +23,6 @@ #include #endif - #include - #include - // Utility structure to help with the epsilon limits for fixed_point. // These special numbers represent the smallest value for a decimal part // that differs from 1 for the corresponding decimal-part width. @@ -972,4 +973,4 @@ return sqrt((x * x) + (y * y)); } -#endif // FIXED_POINT_2011_02_22_H_ +#endif // FIXED_POINT_2011_02_22_H diff --git a/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk b/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk index d9980e747..52ba2a527 100644 --- a/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk +++ b/ref_app/target/micros/atmega2560/make/atmega2560_flags.gmk @@ -1,5 +1,5 @@ # -# Copyright Christopher Kormanyos 2007 - 2024. +# Copyright Christopher Kormanyos 2007 - 2025. # Distributed under the Boost Software License, # Version 1.0. (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -25,7 +25,7 @@ TGT_ALLFLAGS = -Os ifeq ($(TYP_OS),WIN) TGT_ALLFLAGS := $(TGT_ALLFLAGS) \ - -mdouble=32 \ + -mdouble=64 \ -mlong-double=64 endif diff --git a/ref_app/target/micros/atmega4809/make/atmega4809_flags.gmk b/ref_app/target/micros/atmega4809/make/atmega4809_flags.gmk index 29f11b6a3..9f30a37b8 100644 --- a/ref_app/target/micros/atmega4809/make/atmega4809_flags.gmk +++ b/ref_app/target/micros/atmega4809/make/atmega4809_flags.gmk @@ -26,7 +26,7 @@ TGT_ALLFLAGS = -O2 ifeq ($(TYP_OS),WIN) TGT_ALLFLAGS := $(TGT_ALLFLAGS) \ - -mdouble=32 \ + -mdouble=64 \ -mlong-double=64 endif diff --git a/ref_app/target/micros/avr/make/avr_flags.gmk b/ref_app/target/micros/avr/make/avr_flags.gmk index e14278aec..d14522a4e 100644 --- a/ref_app/target/micros/avr/make/avr_flags.gmk +++ b/ref_app/target/micros/avr/make/avr_flags.gmk @@ -25,7 +25,7 @@ TGT_ALLFLAGS = -O2 ifeq ($(TYP_OS),WIN) TGT_ALLFLAGS := $(TGT_ALLFLAGS) \ - -mdouble=32 \ + -mdouble=64 \ -mlong-double=64 endif From 2d1798e84cdbe94c70e448960b6db1c3af368761 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 16:09:46 +0200 Subject: [PATCH 3/7] Place fixed_point class in namespaces --- .../benchmark/app_benchmark_fixed_point.cpp | 4 +- ref_app/src/math/fixed_point/fixed_point.h | 40 +++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_fixed_point.cpp b/ref_app/src/app/benchmark/app_benchmark_fixed_point.cpp index bbcac13d7..96a35a0e0 100644 --- a/ref_app/src/app/benchmark/app_benchmark_fixed_point.cpp +++ b/ref_app/src/app/benchmark/app_benchmark_fixed_point.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2010 - 2019. +// Copyright Christopher Kormanyos 2010 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,7 +18,7 @@ namespace { - using fixed_point_type = fixed_point; + using fixed_point_type = ::math::fixed::fixed_point; } extern fixed_point_type global_a; diff --git a/ref_app/src/math/fixed_point/fixed_point.h b/ref_app/src/math/fixed_point/fixed_point.h index b3bf4feec..508d1aff9 100644 --- a/ref_app/src/math/fixed_point/fixed_point.h +++ b/ref_app/src/math/fixed_point/fixed_point.h @@ -23,6 +23,19 @@ #include #endif + namespace math { namespace fixed { + + // Forward declaration of the fixed_point template class. + template + class fixed_point; + + } // namespace fixed + } // namespace math + + namespace math { namespace fixed { + + namespace detail { + // Utility structure to help with the epsilon limits for fixed_point. // These special numbers represent the smallest value for a decimal part // that differs from 1 for the corresponding decimal-part width. @@ -32,9 +45,7 @@ template<> struct epsilon_helper<16U> { static const std::size_t epsilon_value = std::size_t(7U); }; template<> struct epsilon_helper<32U> { static const std::size_t epsilon_value = std::size_t(44U); }; - // Forward declaration of the fixed_point template class. - template - class fixed_point; + } // namespace detail // The scalable fixed_point template class. template @@ -322,7 +333,7 @@ static fixed_point value_max () { return fixed_point(internal(), signed_value_type((unsigned_value_type(-1LL) - 1U) / 2U)); } static fixed_point value_min () { return fixed_point(internal(), signed_value_type(2L)); } static fixed_point value_half () { return fixed_point(internal(), signed_value_type(1ULL << (decimal_split - 1U))); } - static fixed_point value_eps () { return fixed_point(internal(), signed_value_type(epsilon_helper::epsilon_value)); } + static fixed_point value_eps () { return fixed_point(internal(), signed_value_type(detail::epsilon_helper::epsilon_value)); } static fixed_point value_pi () { return fixed_point(internal(), signed_value_type(0x3243f6A88ULL >> (32U - decimal_split))); } static fixed_point value_pi_half () { return fixed_point(internal(), signed_value_type(0x1921FB544ULL >> (32U - decimal_split))); } static fixed_point value_two_over_pi () { return fixed_point(internal(), signed_value_type(0x0A2F98370ULL >> (32U - decimal_split))); } @@ -545,6 +556,11 @@ template friend inline bool operator> (const fixed_point& b, const fixed_point& a) { return (std::int_least8_t(-a.cmp(b)) > std::int_least8_t(0)); } // Include a few global sample fixed_point functions. + friend inline int fpclassify(const fixed_point& x) + { + return (x.data == signed_value_type(0) ? FP_ZERO : FP_NORMAL); + } + friend inline fixed_point fabs(const fixed_point& x) { return fixed_point(internal(), (x.data < signed_value_type(0) ? -x.data : x.data)); @@ -941,11 +957,14 @@ #endif // !FIXED_POINT_DISABLE_IOSTREAM }; + } // namespace fixed + } // namespace math + // Define the four scalable fixed_point types. - typedef fixed_point fixed_point_3pt4; - typedef fixed_point fixed_point_7pt8; - typedef fixed_point fixed_point_15pt16; - typedef fixed_point fixed_point_31pt32; + typedef math::fixed::fixed_point fixed_point_3pt4; + typedef math::fixed::fixed_point fixed_point_7pt8; + typedef math::fixed::fixed_point fixed_point_15pt16; + typedef math::fixed::fixed_point fixed_point_31pt32; namespace std { @@ -956,6 +975,8 @@ template<> class numeric_limits : public fixed_point_31pt32::my_numeric_limits { }; } + namespace math { namespace fixed { + // Include a few more global sample fixed_point functions. template inline fixed_point_type sqrt(const fixed_point_type& x) { return fixed_point_type(x).calculate_sqrt(); } @@ -973,4 +994,7 @@ return sqrt((x * x) + (y * y)); } + } // namespace fixed + } // namespace math + #endif // FIXED_POINT_2011_02_22_H From e5ee138e3950c7a39e4c069745e20f6e09d8868d Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 16:28:43 +0200 Subject: [PATCH 4/7] Deal with linters --- ref_app/src/app/benchmark/app_benchmark_detail.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ref_app/src/app/benchmark/app_benchmark_detail.h b/ref_app/src/app/benchmark/app_benchmark_detail.h index 201c269f4..36afad2aa 100644 --- a/ref_app/src/app/benchmark/app_benchmark_detail.h +++ b/ref_app/src/app/benchmark/app_benchmark_detail.h @@ -16,7 +16,7 @@ template constexpr auto default_tol() noexcept -> NumericType { - return NumericType { std::numeric_limits::epsilon() * NumericType(100) }; + return NumericType { std::numeric_limits::epsilon() * static_cast(UINT8_C(100)) }; // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) } template @@ -35,7 +35,7 @@ } else { - const NumericType ratio = a / b; + const NumericType ratio { a / b }; closeness = NumericType { fabs(NumericType { 1 - ratio }) }; } From 321daa249bb415ddb66e0bdf89b3e3a40e3f43c5 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 16:36:05 +0200 Subject: [PATCH 5/7] Handle missing header include --- ref_app/src/app/benchmark/app_benchmark_detail.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ref_app/src/app/benchmark/app_benchmark_detail.h b/ref_app/src/app/benchmark/app_benchmark_detail.h index 36afad2aa..7e0afe565 100644 --- a/ref_app/src/app/benchmark/app_benchmark_detail.h +++ b/ref_app/src/app/benchmark/app_benchmark_detail.h @@ -9,6 +9,7 @@ #define APP_BENCHMARK_DETAIL_2018_10_02_H #include + #include #include namespace app { namespace benchmark { namespace detail { From 72e4d7d4f3aa2b3b42a2093c30a9f867030a362b Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 19:31:59 +0200 Subject: [PATCH 6/7] Try repair multi-compiler fpclassify --- ref_app/src/mcal/mcal_gcc_cxx_completion.cpp | 41 +++++++++++++++++++- ref_app/src/util/STL/cmath | 6 +-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp index 2d6a7507d..b5127f44b 100644 --- a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp +++ b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp @@ -9,13 +9,18 @@ #include #include +#include #include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-declarations" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" #endif +int isinf(double); + // Implement std::chrono::high_resolution_clock::now() // for the standard library's high-resolution clock. namespace std @@ -84,12 +89,14 @@ extern "C" { // Declarations of patched functions. + int fpclassifyf(float); + // Provide stubbed copies of certain functions declared in and . // Also provide stubbed copies of certain empirically found library functions // and objects. void abort () __attribute__((noreturn)); - int atexit (void (*)()); + int atexit (void (*)()) noexcept; int at_quick_exit (void (*)()); void _Exit (int) __attribute__((noreturn)); void exit (int) __attribute__((noreturn)); @@ -110,8 +117,37 @@ extern "C" // Implementations of patched functions. + int fpclassifyf(float x) + { + if((::isnanf)(x) != 0) + { + return FP_NAN; + } + else if((::__builtin_isinf)(static_cast(x)) != 0.0) + { + return FP_INFINITE; + } + else if((::fabsf)(x) == 0.0F) + { + return FP_ZERO; + } + else + { + const bool + is_subnormal + { + ( + ((::fabsf)(x) > 0.0F) + && ((::fabsf)(x) < (std::numeric_limits::min)()) + ) + }; + + return (is_subnormal ? FP_SUBNORMAL : FP_NORMAL); + } + } + void abort () { for(;;) { mcal::cpu::nop(); } } - int atexit (void (*)()) { return 0; } + int atexit (void (*)()) noexcept { return 0; } int at_quick_exit (void (*)()) { return 0; } void _Exit (int) { for(;;) { mcal::cpu::nop(); } } void exit (int) { for(;;) { mcal::cpu::nop(); } } @@ -162,4 +198,5 @@ namespace std #if defined(__GNUC__) #pragma GCC diagnostic pop +#pragma GCC diagnostic pop #endif diff --git a/ref_app/src/util/STL/cmath b/ref_app/src/util/STL/cmath index b6b383e59..415597687 100644 --- a/ref_app/src/util/STL/cmath +++ b/ref_app/src/util/STL/cmath @@ -13,7 +13,8 @@ // Implement most of for compilers that do not yet support it. - #if defined(__GNUC__) && defined(__AVR__) + #if (defined(__GNUC__) && defined(__AVR__)) + #include #if !defined(_HUGE_ENUF) @@ -480,9 +481,6 @@ inline int ilogb (float x) { return ::ilogbf(x); } inline int ilogb (double x) { return ::ilogb (x); } inline int ilogb (long double x) { return ::ilogbl(x); } - inline int fpclassify(float x) { return ::fpclassifyf(x); } - inline int fpclassify(double x) { return ::fpclassify (x); } - inline int fpclassify(long double x) { return ::fpclassifyl(x); } #if (defined(__GNUC__) && !defined(__clang__)) inline bool isnan (float x) { return __builtin_isnanf(x); } inline bool isnan (double x) { return __builtin_isnan (x); } From e7b7f0562472c0cbfa9223cd06787fc7f6549e28 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 10 May 2025 21:03:50 +0200 Subject: [PATCH 7/7] Finish and fixed-point syntax --- ref_app/src/math/fixed_point/fixed_point.h | 25 ++- ref_app/src/mcal/mcal_gcc_cxx_completion.cpp | 37 ----- ref_app/src/util/STL/cmath | 157 ++++++++++++------- 3 files changed, 116 insertions(+), 103 deletions(-) diff --git a/ref_app/src/math/fixed_point/fixed_point.h b/ref_app/src/math/fixed_point/fixed_point.h index 508d1aff9..df34cf48b 100644 --- a/ref_app/src/math/fixed_point/fixed_point.h +++ b/ref_app/src/math/fixed_point/fixed_point.h @@ -23,17 +23,16 @@ #include #endif - namespace math { namespace fixed { + #if(__cplusplus >= 201703L) + namespace math::fixed { + #else + namespace math { namespace fixed { // NOLINT(modernize-concat-nested-namespaces) + #endif // Forward declaration of the fixed_point template class. template class fixed_point; - } // namespace fixed - } // namespace math - - namespace math { namespace fixed { - namespace detail { // Utility structure to help with the epsilon limits for fixed_point. @@ -957,8 +956,12 @@ #endif // !FIXED_POINT_DISABLE_IOSTREAM }; + #if(__cplusplus >= 201703L) + } // namespace math::fixed + #else } // namespace fixed } // namespace math + #endif // Define the four scalable fixed_point types. typedef math::fixed::fixed_point fixed_point_3pt4; @@ -975,7 +978,11 @@ template<> class numeric_limits : public fixed_point_31pt32::my_numeric_limits { }; } - namespace math { namespace fixed { + #if(__cplusplus >= 201703L) + namespace math::fixed { + #else + namespace math { namespace fixed { // NOLINT(modernize-concat-nested-namespaces) + #endif // Include a few more global sample fixed_point functions. template @@ -994,7 +1001,11 @@ return sqrt((x * x) + (y * y)); } + #if(__cplusplus >= 201703L) + } // namespace math::fixed + #else } // namespace fixed } // namespace math + #endif #endif // FIXED_POINT_2011_02_22_H diff --git a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp index b5127f44b..65efad943 100644 --- a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp +++ b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp @@ -9,18 +9,13 @@ #include #include -#include #include #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-declarations" -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" #endif -int isinf(double); - // Implement std::chrono::high_resolution_clock::now() // for the standard library's high-resolution clock. namespace std @@ -89,8 +84,6 @@ extern "C" { // Declarations of patched functions. - int fpclassifyf(float); - // Provide stubbed copies of certain functions declared in and . // Also provide stubbed copies of certain empirically found library functions // and objects. @@ -117,35 +110,6 @@ extern "C" // Implementations of patched functions. - int fpclassifyf(float x) - { - if((::isnanf)(x) != 0) - { - return FP_NAN; - } - else if((::__builtin_isinf)(static_cast(x)) != 0.0) - { - return FP_INFINITE; - } - else if((::fabsf)(x) == 0.0F) - { - return FP_ZERO; - } - else - { - const bool - is_subnormal - { - ( - ((::fabsf)(x) > 0.0F) - && ((::fabsf)(x) < (std::numeric_limits::min)()) - ) - }; - - return (is_subnormal ? FP_SUBNORMAL : FP_NORMAL); - } - } - void abort () { for(;;) { mcal::cpu::nop(); } } int atexit (void (*)()) noexcept { return 0; } int at_quick_exit (void (*)()) { return 0; } @@ -198,5 +162,4 @@ namespace std #if defined(__GNUC__) #pragma GCC diagnostic pop -#pragma GCC diagnostic pop #endif diff --git a/ref_app/src/util/STL/cmath b/ref_app/src/util/STL/cmath index 415597687..4ec073b48 100644 --- a/ref_app/src/util/STL/cmath +++ b/ref_app/src/util/STL/cmath @@ -235,25 +235,49 @@ double atanh (double x); long double atanhl(long double x); - int fpclassifyf(float x); - int fpclassify (double x); + //int isfinitef(float x); + int isfinitel(long double x); + int ilogbf(float x); + int ilogb (double x); + int ilogbl(long double x); + + float tgammaf(float x); + double tgamma (double x); + long double tgammal(long double x); + + float lgammaf(float x); + double lgamma (double x); + long double lgammal(long double x); + } + + namespace std + { + inline bool isfinite (float x) { return ::isfinitef(x) == 1; } + inline bool isfinite (double x) { return ::isfinite (x) == 1; } + inline bool isfinite (long double x) { return ::isfinitel(x) == 1; } + inline bool isnan (float x) { return __BUILTIN_ISNANF (x) == 1; } + inline bool isnan (double x) { return __BUILTIN_ISNAN (x) == 1; } + inline bool isnan (long double x) { return __BUILTIN_ISNANL (x) == 1; } + inline float fabs (float x) { return __BUILTIN_FABSF (x); } + inline double fabs (double x) { return __BUILTIN_FABS (x); } + inline long double fabs (long double x) { return __BUILTIN_FABSL (x); } - static inline int fpclassifyl(long double x) + inline int fpclassify(double x) { #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif - if((::__BUILTIN_ISNANL)(x) != 0) + if((isnan)(x) != 0) { return FP_NAN; } - else if((::__BUILTIN_ISINFL)(x) != 0.0L) + else if((isinf)(x) != 0.0) { return FP_INFINITE; } - else if((::__BUILTIN_FABSL)(x) == 0.0L) + else if((fabs)(x) == 0.0) { return FP_ZERO; } @@ -263,8 +287,8 @@ is_subnormal { ( - ((::__BUILTIN_FABSL)(x) > 0.0L) - && ((::__BUILTIN_FABSL)(x) < (std::numeric_limits::min)()) + ((fabs)(x) > 0.0) + && ((fabs)(x) < (std::numeric_limits::min)()) ) }; @@ -276,38 +300,12 @@ #endif } - //int isfinitef(float x); - int isfinitel(long double x); - int ilogbf(float x); - int ilogb (double x); - int ilogbl(long double x); - - float tgammaf(float x); - double tgamma (double x); - long double tgammal(long double x); + inline int fpclassify(float x) { return fpclassify(static_cast(x)); } + inline int fpclassify(long double x) { return fpclassify(static_cast(x)); } - float lgammaf(float x); - double lgamma (double x); - long double lgammal(long double x); - } - - namespace std - { - inline bool isfinite (float x) { return ::isfinitef(x) == 1; } - inline bool isfinite (double x) { return ::isfinite (x) == 1; } - inline bool isfinite (long double x) { return ::isfinitel(x) == 1; } inline int ilogb (float x) { return ::ilogbf (x); } inline int ilogb (double x) { return ::ilogb (x); } inline int ilogb (long double x) { return ::ilogbl (x); } - inline int fpclassify(float x) { return ::fpclassifyf(x); } - inline int fpclassify(double x) { return ::fpclassify (x); } - inline int fpclassify(long double x) { return ::fpclassifyl(x); } - inline bool isnan (float x) { return __BUILTIN_ISNANF (x) == 1; } - inline bool isnan (double x) { return __BUILTIN_ISNAN (x) == 1; } - inline bool isnan (long double x) { return __BUILTIN_ISNANL (x) == 1; } - inline float fabs (float x) { return __BUILTIN_FABSF (x); } - inline double fabs (double x) { return __BUILTIN_FABS (x); } - inline long double fabs (long double x) { return __BUILTIN_FABSL (x); } inline float fmod (float x, float y) { return __BUILTIN_FMODF (x, y); } inline double fmod (double x, double y) { return __BUILTIN_FMOD (x, y); } inline long double fmod (long double x, long double y) { return __BUILTIN_FMODL (x, y); } @@ -419,8 +417,6 @@ long double ceill (long double x); float frexpf (float x, int* p); long double frexpl (long double x, int* p); - int fpclassifyf(float x); - int fpclassifyl(long double x); float ldexpf (float x, int p); long double ldexpl (long double x, int p); long lroundf (float x); @@ -585,9 +581,6 @@ inline float frexp (float x, int* p) { return ::frexpf(x, p); } extern "C" double frexp (double x, int* p); inline long double frexp (long double x, int* p) { return ::frexpl(x, p); } - inline int fpclassify(float x) { return ::fpclassifyf (x); } - extern "C" int fpclassify(double x); - inline int fpclassify(long double x) { return ::fpclassifyl (x); } inline float ldexp (float x, int p) { return ::ldexpf(x, p); } extern "C" double ldexp (double x, int p); inline long double ldexp (long double x, int p) { return ::ldexpl (x, p); } @@ -658,7 +651,7 @@ inline float lgamma (float x) { return ::lgammaf(x); } extern "C" double lgamma (double x); inline long double lgamma (long double x) { return ::lgammal(x); } - #if __cplusplus > 201703L + #if (defined(__cplusplus) && (__cplusplus > 201703L)) inline float lerp (float a, float b, float t) { return a + (t * (b - a)); } inline double lerp (double a, double b, double t) { return a + (t * (b - a)); } inline long double lerp (long double a, long double b, long double t) @@ -668,15 +661,77 @@ } #endif + #if !defined(FP_INFINITE) + #define FP_INFINITE 1 + #endif + #if !defined(FP_NAN) + #define FP_NAN 2 + #endif + #if !defined(FP_NORMAL) + #define FP_NORMAL (-1) + #endif + #if !defined(FP_SUBNORMAL) + #define FP_SUBNORMAL (-2) + #endif + #if !defined(FP_ZERO) + #define FP_ZERO 0 + #endif + namespace std { using ::isfinite; using ::ilogb; + + inline bool isinf(double x) { return ((x == std::numeric_limits::infinity()) || (-x == std::numeric_limits::infinity())); } + inline bool isinf(float x) { return isinf(static_cast(x)); } + inline bool isinf(long double x) { return isinf(static_cast(x)); } + using ::isnan; using ::abs; using ::fabs; using ::fmod; - using ::fpclassify; + + inline int fpclassify(double x) + { + #if defined(__GNUC__) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wfloat-equal" + #endif + + if((isnan)(x) != 0) + { + return FP_NAN; + } + else if((isinf)(x) != 0.0) + { + return FP_INFINITE; + } + else if((fabs)(x) == 0.0) + { + return FP_ZERO; + } + else + { + const bool + is_subnormal + { + ( + ((fabs)(x) > 0.0) + && ((fabs)(x) < (std::numeric_limits::min)()) + ) + }; + + return (is_subnormal ? FP_SUBNORMAL : FP_NORMAL); + } + + #if defined(__GNUC__) + #pragma GCC diagnostic pop + #endif + } + + inline int fpclassify(float x) { return fpclassify(static_cast(x)); } + inline int fpclassify(long double x) { return fpclassify(static_cast(x)); } + using ::modf; using ::floor; using ::ceil; @@ -708,20 +763,4 @@ #endif - #if !defined(FP_INFINITE) - #define FP_INFINITE 1 - #endif - #if !defined(FP_NAN) - #define FP_NAN 2 - #endif - #if !defined(FP_NORMAL) - #define FP_NORMAL (-1) - #endif - #if !defined(FP_SUBNORMAL) - #define FP_SUBNORMAL (-2) - #endif - #if !defined(FP_ZERO) - #define FP_ZERO 0 - #endif - #endif // CMATH_2010_02_23_