FloatSpec does not use non-standard C lib anymore

This commit is contained in:
Pavel Kirienko
2014-03-25 03:25:08 +04:00
parent 7a3790b460
commit 7ff5630eaa
+35 -2
View File
@@ -2,9 +2,18 @@
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#include <uavcan/impl_constants.hpp>
#include <uavcan/marshal/float_spec.hpp>
#include <cmath>
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
# error UAVCAN_CPP_VERSION
#endif
#undef signbit
#undef isnan
#undef isinf
namespace uavcan
{
/*
@@ -15,7 +24,31 @@ namespace uavcan
template <typename T>
static inline bool signbit(T arg)
{
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
return std::signbit(arg);
#else
return arg < T(0) || (arg == T(0) && T(1) / arg < T(0));
#endif
}
template <typename T>
static inline bool isnan(T arg)
{
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
return std::isnan(arg);
#else
return arg != arg;
#endif
}
template <typename T>
static inline bool isinf(T arg)
{
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
return std::isinf(arg);
#else
return arg == std::numeric_limits<T>::infinity() || arg == -std::numeric_limits<T>::infinity();
#endif
}
uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
@@ -25,11 +58,11 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
{
return hbits;
}
if (isnanf(value))
if (isnan(value))
{
return hbits | 0x7FFF;
}
if (isinff(value))
if (isinf(value))
{
return hbits | 0x7C00;
}