diff options
author | Tim Shen <timshen@google.com> | 2020-09-14 17:32:56 -0700 |
---|---|---|
committer | Tim Shen <timshen@google.com> | 2020-09-15 13:24:23 -0700 |
commit | bb56a62582929d4b3b0a73e49d19909b6b319f79 (patch) | |
tree | b50d3e8a126a8036b08f75c18dc1ebbacb6aa54c /Eigen/src/Core | |
parent | 3012e755e92d3b3f01f8e7753b5e71cbeaaa40df (diff) |
Make bfloat16(float(-nan)) produce -nan, not nan.
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r-- | Eigen/src/Core/arch/Default/BFloat16.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Eigen/src/Core/arch/Default/BFloat16.h b/Eigen/src/Core/arch/Default/BFloat16.h index 30f3cd456..3b36c2f23 100644 --- a/Eigen/src/Core/arch/Default/BFloat16.h +++ b/Eigen/src/Core/arch/Default/BFloat16.h @@ -256,7 +256,7 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator / (const bfloat16& a, In EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw truncate_to_bfloat16(const float v) { __bfloat16_raw output; if (Eigen::numext::isnan EIGEN_NOT_A_MACRO(v)) { - output.value = 0x7FC0; + output.value = std::signbit(v) ? 0xFFC0: 0x7FC0; return output; } else if (std::fabs(v) < std::numeric_limits<float>::min EIGEN_NOT_A_MACRO()) { // Flush denormal to +/- 0. @@ -293,7 +293,7 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne<fals // // qNaN magic: All exponent bits set + most significant bit of fraction // set. - output.value = 0x7fc0; + output.value = std::signbit(ff) ? 0xFFC0: 0x7FC0; } else if (std::fabs(ff) < std::numeric_limits<float>::min EIGEN_NOT_A_MACRO()) { // Flush denormal to +/- 0.0 output.value = std::signbit(ff) ? 0x8000 : 0; |