Skip to content

Commit 84d54f2

Browse files
committed
Correct design error isfinite() on AVR
1 parent 53a5b85 commit 84d54f2

1 file changed

Lines changed: 4 additions & 24 deletions

File tree

  • ref_app/src/util/STL

ref_app/src/util/STL/cmath

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,30 +250,6 @@
250250

251251
namespace std
252252
{
253-
namespace cmath_detail {
254-
255-
__attribute__((always_inline)) static inline int isfinitef_impl(float my_x)
256-
{
257-
unsigned char my_exp { };
258-
259-
asm volatile
260-
(
261-
"mov %0, %C1" "\n\t"
262-
"lsl %0" "\n\t"
263-
"mov %0, %D1" "\n\t"
264-
"rol %0"
265-
: "=&r" (my_exp)
266-
: "r" (my_x)
267-
);
268-
269-
return ((my_exp != static_cast<unsigned char>(0xFFU)) ? 1 : 0);
270-
}
271-
272-
} // namespace cmath_detail
273-
274-
inline bool isfinite (float x) { return (::std::cmath_detail::isfinitef_impl(x) == 1); }
275-
inline bool isfinite (double x) { return (::std::cmath_detail::isfinitef_impl(static_cast<float>(x)) == 1); }
276-
inline bool isfinite (long double x) { return (::std::cmath_detail::isfinitef_impl(static_cast<float>(x)) == 1); }
277253
inline bool isnan (float x) { return (__BUILTIN_ISNANF(x) == 1); }
278254
inline bool isnan (double x) { return (__BUILTIN_ISNAN (x) == 1); }
279255
inline bool isnan (long double x) { return (__BUILTIN_ISNANL(x) == 1); }
@@ -293,6 +269,10 @@
293269
inline bool isinf(double x) { return ::std::cmath_detail::isinf_impl(x); }
294270
inline bool isinf(long double x) { return ::std::cmath_detail::isinf_impl(x); }
295271

272+
inline bool isfinite(float x) { return ((!(::std::isinf)(x)) && (!(::std::isnan)(x))); }
273+
inline bool isfinite(double x) { return ((!(::std::isinf)(x)) && (!(::std::isnan)(x))); }
274+
inline bool isfinite(long double x) { return ((!(::std::isinf)(x)) && (!(::std::isnan)(x))); }
275+
296276
namespace cmath_detail {
297277

298278
template<typename FloatType>

0 commit comments

Comments
 (0)