-
Notifications
You must be signed in to change notification settings - Fork 28
<cmath> does not publish std::fpclassify() #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The compiler has a A very simple implementation (if that's needed) goes something like this: #if !defined(FP_NAN)
#define FP_NAN 0
#endif
#if !defined(FP_INFINITE)
#define FP_INFINITE 1
#endif
#if !defined(FP_ZERO)
#define FP_ZERO 2
#endif
#if !defined(FP_SUBNORMAL)
#define FP_SUBNORMAL 3
#endif
#if !defined(FP_NORMAL)
#define FP_NORMAL 4
#endif
namespace std {
// a bunch of other stuff, also isnan, fabs, and more...
namespace cmath_detail {
template<typename FloatType>
inline int fpclassify_impl(FloatType x)
{
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
using float_type = FloatType;
if((::std::isnan)(x))
{
return FP_NAN;
}
else if((::std::isinf)(x))
{
return FP_INFINITE;
}
else if((::std::fabs)(x) == static_cast<float_type>(0.0L))
{
return FP_ZERO;
}
else
{
const bool
is_subnormal
{
(
((::std::fabs)(x) > static_cast<float_type>(0.0L))
&& ((::std::fabs)(x) < (std::numeric_limits<float_type>::min)())
)
};
return (is_subnormal ? FP_SUBNORMAL : FP_NORMAL);
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
} // namespace cmath_detail
inline int fpclassify(float x) { return ::std::cmath_detail::fpclassify_impl(x); }
inline int fpclassify(double x) { return ::std::cmath_detail::fpclassify_impl(x); }
inline int fpclassify(long double x) { return ::std::cmath_detail::fpclassify_impl(x); }
} // namespace std |
I don't think you need to define it. If you have the constants, you can use the compiler built-in. I think that is always expanded by the compiler, so doesn't require anything from avr-libc to work (just the constants).
In upstream libstdc++ this gets set when configuring GCC, based on this autoconf test:
We test that separately for C++98 mode and C++11 mode and define separate So libstdc++ will not define any of
This is defined if libc already provides
This is only relevant for OpenBSD and vxworks. |
I opened https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120232 upstream. I don't plan to work on it any time soon though (and it wouldn't help avr-libstdcpp unless you sync with upstream). |
See also #41. Thanks @jwakely I actually think a naive exclusion of C++11 functions was the culprit in this problem. I did a trivial fix. I could not believe that this is upstream. But you might want to check anyway. Cc: @salkinium and @chris-durand |
This partially reverts 5a4c53d and adds the constants needed for it to work. Fixes: modm-io#40
This partially reverts 5a4c53d and adds the constants needed for it to work. Fixes: modm-io#40
Uh oh!
There was an error while loading. Please reload this page.
I was doing some standard mathematical calculations and I found empirically that
<cmath>
does not publishstd::fpclassify
.FP_NAN
,FP_INFINITE
,FP_NORMAL
,FP_SUBNORMAL
andFP_ZERO
.There is an implementation of
fpclassify
instd
present in the file, but it is hidden within some compiler switches that I don't understand. It is rather straightforward to implement, if that is the answer here.If I'm not mistaken, I think we need in namespace
std
:And I think we also need the constants
FP_NAN
,FP_INFINITE
,FP_NORMAL
,FP_SUBNORMAL
andFP_ZERO
.The text was updated successfully, but these errors were encountered: