Skip to content

Commit 72e4d7d

Browse files
committed
Try repair multi-compiler fpclassify
1 parent 321daa2 commit 72e4d7d

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

ref_app/src/mcal/mcal_gcc_cxx_completion.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
#include <mcal_gpt.h>
1010

1111
#include <chrono>
12+
#include <cmath>
1213
#include <cstddef>
1314

1415
#if defined(__GNUC__)
1516
#pragma GCC diagnostic push
1617
#pragma GCC diagnostic ignored "-Wmissing-declarations"
18+
#pragma GCC diagnostic push
19+
#pragma GCC diagnostic ignored "-Wfloat-equal"
1720
#endif
1821

22+
int isinf(double);
23+
1924
// Implement std::chrono::high_resolution_clock::now()
2025
// for the standard library's high-resolution clock.
2126
namespace std
@@ -84,12 +89,14 @@ extern "C"
8489
{
8590
// Declarations of patched functions.
8691

92+
int fpclassifyf(float);
93+
8794
// Provide stubbed copies of certain functions declared in <stdlib.h> and <cstdlib>.
8895
// Also provide stubbed copies of certain empirically found library functions
8996
// and objects.
9097

9198
void abort () __attribute__((noreturn));
92-
int atexit (void (*)());
99+
int atexit (void (*)()) noexcept;
93100
int at_quick_exit (void (*)());
94101
void _Exit (int) __attribute__((noreturn));
95102
void exit (int) __attribute__((noreturn));
@@ -110,8 +117,37 @@ extern "C"
110117

111118
// Implementations of patched functions.
112119

120+
int fpclassifyf(float x)
121+
{
122+
if((::isnanf)(x) != 0)
123+
{
124+
return FP_NAN;
125+
}
126+
else if((::__builtin_isinf)(static_cast<double>(x)) != 0.0)
127+
{
128+
return FP_INFINITE;
129+
}
130+
else if((::fabsf)(x) == 0.0F)
131+
{
132+
return FP_ZERO;
133+
}
134+
else
135+
{
136+
const bool
137+
is_subnormal
138+
{
139+
(
140+
((::fabsf)(x) > 0.0F)
141+
&& ((::fabsf)(x) < (std::numeric_limits<float>::min)())
142+
)
143+
};
144+
145+
return (is_subnormal ? FP_SUBNORMAL : FP_NORMAL);
146+
}
147+
}
148+
113149
void abort () { for(;;) { mcal::cpu::nop(); } }
114-
int atexit (void (*)()) { return 0; }
150+
int atexit (void (*)()) noexcept { return 0; }
115151
int at_quick_exit (void (*)()) { return 0; }
116152
void _Exit (int) { for(;;) { mcal::cpu::nop(); } }
117153
void exit (int) { for(;;) { mcal::cpu::nop(); } }
@@ -162,4 +198,5 @@ namespace std
162198

163199
#if defined(__GNUC__)
164200
#pragma GCC diagnostic pop
201+
#pragma GCC diagnostic pop
165202
#endif

ref_app/src/util/STL/cmath

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
// Implement most of <cmath> for compilers that do not yet support it.
1515

16-
#if defined(__GNUC__) && defined(__AVR__)
16+
#if (defined(__GNUC__) && defined(__AVR__))
17+
1718
#include <math.h>
1819

1920
#if !defined(_HUGE_ENUF)
@@ -480,9 +481,6 @@
480481
inline int ilogb (float x) { return ::ilogbf(x); }
481482
inline int ilogb (double x) { return ::ilogb (x); }
482483
inline int ilogb (long double x) { return ::ilogbl(x); }
483-
inline int fpclassify(float x) { return ::fpclassifyf(x); }
484-
inline int fpclassify(double x) { return ::fpclassify (x); }
485-
inline int fpclassify(long double x) { return ::fpclassifyl(x); }
486484
#if (defined(__GNUC__) && !defined(__clang__))
487485
inline bool isnan (float x) { return __builtin_isnanf(x); }
488486
inline bool isnan (double x) { return __builtin_isnan (x); }

0 commit comments

Comments
 (0)