Some fixes/cleanups for numeric_limits & fix for related bug in psqrt

This commit is contained in:
Rasmus Munk Larsen
2022-01-07 01:10:17 +00:00
parent ed27d988c1
commit 96dc37a03b
6 changed files with 43 additions and 27 deletions

View File

@@ -137,21 +137,25 @@ struct numeric_limits<Eigen::bfloat16> {
static EIGEN_CONSTEXPR const bool has_infinity = true;
static EIGEN_CONSTEXPR const bool has_quiet_NaN = true;
static EIGEN_CONSTEXPR const bool has_signaling_NaN = true;
static EIGEN_CONSTEXPR const float_denorm_style has_denorm = std::denorm_absent;
static EIGEN_CONSTEXPR const float_denorm_style has_denorm = std::denorm_present;
static EIGEN_CONSTEXPR const bool has_denorm_loss = false;
static EIGEN_CONSTEXPR const std::float_round_style round_style = numeric_limits<float>::round_style;
static EIGEN_CONSTEXPR const bool is_iec559 = false;
static EIGEN_CONSTEXPR const bool is_iec559 = true;
// The C++ standard defines this as "true if the set of values representable
// by the type is finite." BFloat16 has finite precision.
static EIGEN_CONSTEXPR const bool is_bounded = true;
static EIGEN_CONSTEXPR const bool is_modulo = false;
static EIGEN_CONSTEXPR const int digits = 8;
static EIGEN_CONSTEXPR const int digits10 = 2;
static EIGEN_CONSTEXPR const int max_digits10 = 4;
static EIGEN_CONSTEXPR const int radix = 2;
static EIGEN_CONSTEXPR const int radix = numeric_limits<float>::radix;
static EIGEN_CONSTEXPR const int min_exponent = numeric_limits<float>::min_exponent;
static EIGEN_CONSTEXPR const int min_exponent10 = numeric_limits<float>::min_exponent10;
static EIGEN_CONSTEXPR const int max_exponent = numeric_limits<float>::max_exponent;
static EIGEN_CONSTEXPR const int max_exponent10 = numeric_limits<float>::max_exponent10;
static EIGEN_CONSTEXPR const bool traps = numeric_limits<float>::traps;
// IEEE754: "The implementer shall choose how tininess is detected, but shall
// detect tininess in the same way for all operations in radix two"
static EIGEN_CONSTEXPR const bool tinyness_before = numeric_limits<float>::tinyness_before;
static EIGEN_CONSTEXPR Eigen::bfloat16 (min)() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x0080); }
@@ -161,7 +165,7 @@ struct numeric_limits<Eigen::bfloat16> {
static EIGEN_CONSTEXPR Eigen::bfloat16 round_error() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x3f00); }
static EIGEN_CONSTEXPR Eigen::bfloat16 infinity() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7f80); }
static EIGEN_CONSTEXPR Eigen::bfloat16 quiet_NaN() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7fc0); }
static EIGEN_CONSTEXPR Eigen::bfloat16 signaling_NaN() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7f81); }
static EIGEN_CONSTEXPR Eigen::bfloat16 signaling_NaN() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x7fa0); }
static EIGEN_CONSTEXPR Eigen::bfloat16 denorm_min() { return Eigen::bfloat16_impl::raw_uint16_to_bfloat16(0x0001); }
};

View File

@@ -218,29 +218,33 @@ struct numeric_limits<Eigen::half> {
static EIGEN_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
static EIGEN_CONSTEXPR const bool has_denorm_loss = false;
static EIGEN_CONSTEXPR const std::float_round_style round_style = std::round_to_nearest;
static EIGEN_CONSTEXPR const bool is_iec559 = false;
static EIGEN_CONSTEXPR const bool is_bounded = false;
static EIGEN_CONSTEXPR const bool is_iec559 = true;
// The C++ standard defines this as "true if the set of values representable
// by the type is finite." Half has finite precision.
static EIGEN_CONSTEXPR const bool is_bounded = true;
static EIGEN_CONSTEXPR const bool is_modulo = false;
static EIGEN_CONSTEXPR const int digits = 11;
static EIGEN_CONSTEXPR const int digits10 = 3; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html
static EIGEN_CONSTEXPR const int max_digits10 = 5; // according to http://half.sourceforge.net/structstd_1_1numeric__limits_3_01half__float_1_1half_01_4.html
static EIGEN_CONSTEXPR const int radix = 2;
static EIGEN_CONSTEXPR const int radix = numeric_limits<float>::radix;
static EIGEN_CONSTEXPR const int min_exponent = -13;
static EIGEN_CONSTEXPR const int min_exponent10 = -4;
static EIGEN_CONSTEXPR const int max_exponent = 16;
static EIGEN_CONSTEXPR const int max_exponent10 = 4;
static EIGEN_CONSTEXPR const bool traps = true;
static EIGEN_CONSTEXPR const bool tinyness_before = false;
static EIGEN_CONSTEXPR const bool traps = numeric_limits<float>::traps;
// IEEE754: "The implementer shall choose how tininess is detected, but shall
// detect tininess in the same way for all operations in radix two"
static EIGEN_CONSTEXPR const bool tinyness_before = std::numeric_limits<float>::tinyness_before;
static EIGEN_CONSTEXPR Eigen::half (min)() { return Eigen::half_impl::raw_uint16_to_half(0x400); }
static EIGEN_CONSTEXPR Eigen::half (min)() { return Eigen::half_impl::raw_uint16_to_half(0x0400); }
static EIGEN_CONSTEXPR Eigen::half lowest() { return Eigen::half_impl::raw_uint16_to_half(0xfbff); }
static EIGEN_CONSTEXPR Eigen::half (max)() { return Eigen::half_impl::raw_uint16_to_half(0x7bff); }
static EIGEN_CONSTEXPR Eigen::half epsilon() { return Eigen::half_impl::raw_uint16_to_half(0x0800); }
static EIGEN_CONSTEXPR Eigen::half epsilon() { return Eigen::half_impl::raw_uint16_to_half(0x1400); }
static EIGEN_CONSTEXPR Eigen::half round_error() { return Eigen::half_impl::raw_uint16_to_half(0x3800); }
static EIGEN_CONSTEXPR Eigen::half infinity() { return Eigen::half_impl::raw_uint16_to_half(0x7c00); }
static EIGEN_CONSTEXPR Eigen::half quiet_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); }
static EIGEN_CONSTEXPR Eigen::half signaling_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7d00); }
static EIGEN_CONSTEXPR Eigen::half denorm_min() { return Eigen::half_impl::raw_uint16_to_half(0x1); }
static EIGEN_CONSTEXPR Eigen::half denorm_min() { return Eigen::half_impl::raw_uint16_to_half(0x0001); }
};
// If std::numeric_limits<T> is specialized, should also specialize