mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-19 08:09:36 +08:00
Add missing std::numeric_limits specialization for half, and complete NumTraits<half>
This commit is contained in:
parent
682b2ef17e
commit
d588822779
@ -493,9 +493,59 @@ template<> struct is_arithmetic<half> { enum { value = true }; };
|
|||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
|
||||||
|
} // end namespace Eigen
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
template<>
|
||||||
|
struct numeric_limits<Eigen::half> {
|
||||||
|
static const bool is_specialized = true;
|
||||||
|
static const bool is_signed = true;
|
||||||
|
static const bool is_integer = false;
|
||||||
|
static const bool is_exact = false;
|
||||||
|
static const bool has_infinity = true;
|
||||||
|
static const bool has_quiet_NaN = true;
|
||||||
|
static const bool has_signaling_NaN = true;
|
||||||
|
static const float_denorm_style has_denorm = denorm_present;
|
||||||
|
static const bool has_denorm_loss = false;
|
||||||
|
std::float_round_style round_style = std::round_to_nearest;
|
||||||
|
static const bool is_iec559 = false;
|
||||||
|
static const bool is_bounded = false;
|
||||||
|
static const bool is_modulo = false;
|
||||||
|
static const int digits = 11;
|
||||||
|
static const int digits10 = 2;
|
||||||
|
//static const int max_digits10 = ;
|
||||||
|
static const int radix = 2;
|
||||||
|
static const int min_exponent = -13;
|
||||||
|
static const int min_exponent10 = -4;
|
||||||
|
static const int max_exponent = 16;
|
||||||
|
static const int max_exponent10 = 4;
|
||||||
|
static const bool traps = true;
|
||||||
|
static const bool tinyness_before = false;
|
||||||
|
|
||||||
|
static Eigen::half (min)() { return Eigen::half_impl::raw_uint16_to_half(0x400); }
|
||||||
|
static Eigen::half lowest() { return Eigen::half_impl::raw_uint16_to_half(0xfbff); }
|
||||||
|
static Eigen::half (max)() { return Eigen::half_impl::raw_uint16_to_half(0x7bff); }
|
||||||
|
static Eigen::half epsilon() { return Eigen::half_impl::raw_uint16_to_half(0x0800); }
|
||||||
|
static Eigen::half round_error() { return epsilon()/2; }
|
||||||
|
static Eigen::half infinity() { return Eigen::half_impl::raw_uint16_to_half(0x7c00); }
|
||||||
|
static Eigen::half quiet_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); }
|
||||||
|
static Eigen::half signaling_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); }
|
||||||
|
static Eigen::half denorm_min() { return Eigen::half_impl::raw_uint16_to_half(0x1); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Eigen {
|
||||||
|
|
||||||
template<> struct NumTraits<Eigen::half>
|
template<> struct NumTraits<Eigen::half>
|
||||||
: GenericNumTraits<Eigen::half>
|
: GenericNumTraits<Eigen::half>
|
||||||
{
|
{
|
||||||
|
enum {
|
||||||
|
IsSigned = true,
|
||||||
|
IsInteger = false,
|
||||||
|
IsComplex = false,
|
||||||
|
RequireInitialization = false
|
||||||
|
};
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half epsilon() {
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Eigen::half epsilon() {
|
||||||
return half_impl::raw_uint16_to_half(0x0800);
|
return half_impl::raw_uint16_to_half(0x0800);
|
||||||
}
|
}
|
||||||
|
@ -96,12 +96,24 @@ void test_conversion()
|
|||||||
|
|
||||||
void test_numtraits()
|
void test_numtraits()
|
||||||
{
|
{
|
||||||
std::cout << "epsilon = " << NumTraits<half>::epsilon() << std::endl;
|
std::cout << "epsilon = " << NumTraits<half>::epsilon() << " (0x" << std::hex << NumTraits<half>::epsilon().x << ")" << std::endl;
|
||||||
std::cout << "highest = " << NumTraits<half>::highest() << std::endl;
|
std::cout << "highest = " << NumTraits<half>::highest() << " (0x" << std::hex << NumTraits<half>::highest().x << ")" << std::endl;
|
||||||
std::cout << "lowest = " << NumTraits<half>::lowest() << std::endl;
|
std::cout << "lowest = " << NumTraits<half>::lowest() << " (0x" << std::hex << NumTraits<half>::lowest().x << ")" << std::endl;
|
||||||
std::cout << "inifinty = " << NumTraits<half>::infinity() << std::endl;
|
std::cout << "min = " << (std::numeric_limits<half>::min)() << " (0x" << std::hex << half((std::numeric_limits<half>::min)()).x << ")" << std::endl;
|
||||||
std::cout << "nan = " << NumTraits<half>::quiet_NaN() << std::endl;
|
std::cout << "denorm min = " << (std::numeric_limits<half>::denorm_min)() << " (0x" << std::hex << half((std::numeric_limits<half>::denorm_min)()).x << ")" << std::endl;
|
||||||
|
std::cout << "infinity = " << NumTraits<half>::infinity() << " (0x" << std::hex << NumTraits<half>::infinity().x << ")" << std::endl;
|
||||||
|
std::cout << "quiet nan = " << NumTraits<half>::quiet_NaN() << " (0x" << std::hex << NumTraits<half>::quiet_NaN().x << ")" << std::endl;
|
||||||
|
std::cout << "signaling nan = " << std::numeric_limits<half>::signaling_NaN() << " (0x" << std::hex << std::numeric_limits<half>::signaling_NaN().x << ")" << std::endl;
|
||||||
|
|
||||||
|
VERIFY(NumTraits<half>::IsSigned);
|
||||||
|
|
||||||
|
VERIFY_IS_EQUAL( std::numeric_limits<half>::infinity().x, half(std::numeric_limits<float>::infinity()).x );
|
||||||
|
VERIFY_IS_EQUAL( std::numeric_limits<half>::quiet_NaN().x, half(std::numeric_limits<float>::quiet_NaN()).x );
|
||||||
|
VERIFY_IS_EQUAL( std::numeric_limits<half>::signaling_NaN().x, half(std::numeric_limits<float>::signaling_NaN()).x );
|
||||||
|
VERIFY( (std::numeric_limits<half>::min)() > half(0.f) );
|
||||||
|
VERIFY( (std::numeric_limits<half>::denorm_min)() > half(0.f) );
|
||||||
|
VERIFY( (std::numeric_limits<half>::min)()/2 > half(0.f) );
|
||||||
|
VERIFY_IS_EQUAL( (std::numeric_limits<half>::denorm_min)()/2, half(0.f) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_arithmetic()
|
void test_arithmetic()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user