mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 04:53:33 +08:00
FloatSpec does not use non-standard C lib anymore
This commit is contained in:
@@ -2,9 +2,18 @@
|
|||||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <uavcan/impl_constants.hpp>
|
||||||
#include <uavcan/marshal/float_spec.hpp>
|
#include <uavcan/marshal/float_spec.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
|
||||||
|
# error UAVCAN_CPP_VERSION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef signbit
|
||||||
|
#undef isnan
|
||||||
|
#undef isinf
|
||||||
|
|
||||||
namespace uavcan
|
namespace uavcan
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -15,7 +24,31 @@ namespace uavcan
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static inline bool signbit(T arg)
|
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));
|
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)
|
uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
|
||||||
@@ -25,11 +58,11 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
|
|||||||
{
|
{
|
||||||
return hbits;
|
return hbits;
|
||||||
}
|
}
|
||||||
if (isnanf(value))
|
if (isnan(value))
|
||||||
{
|
{
|
||||||
return hbits | 0x7FFF;
|
return hbits | 0x7FFF;
|
||||||
}
|
}
|
||||||
if (isinff(value))
|
if (isinf(value))
|
||||||
{
|
{
|
||||||
return hbits | 0x7C00;
|
return hbits | 0x7C00;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user