Skip to content

Commit ec0bda9

Browse files
committed
Alter handling of nan arguments
1 parent 6586c92 commit ec0bda9

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

include/boost/decimal/decimal32_t.hpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,15 +1896,32 @@ constexpr auto div_impl(const decimal32_t lhs, const decimal32_t rhs, decimal32_
18961896

18971897
const auto lhs_fp {fpclassify(lhs)};
18981898
const auto rhs_fp {fpclassify(rhs)};
1899-
1900-
if (lhs_fp == FP_NAN || rhs_fp == FP_NAN)
1899+
1900+
if (lhs_fp != FP_NORMAL || rhs_fp != FP_NORMAL)
19011901
{
1902-
// Operations on an SNAN return a QNAN with the same payload
1903-
decimal32_t return_nan {};
1904-
if (lhs_fp == FP_NAN)
1902+
if (lhs_fp == FP_NAN || rhs_fp == FP_NAN)
19051903
{
1906-
return_nan = issignaling(lhs) ? nan_conversion(lhs) : lhs;
1907-
}
1904+
// Operations on an SNAN return a QNAN with the same payload
1905+
decimal32_t return_nan {};
1906+
if (lhs_fp == rhs_fp)
1907+
{
1908+
// They are both NANs
1909+
const bool lhs_signaling {issignaling(lhs)};
1910+
const bool rhs_signaling {issignaling(rhs)};
1911+
1912+
if (!lhs_signaling && rhs_signaling)
1913+
{
1914+
return_nan = nan_conversion(rhs);
1915+
}
1916+
else
1917+
{
1918+
return_nan = lhs_signaling ? nan_conversion(lhs) : lhs;
1919+
}
1920+
}
1921+
else if (lhs_fp == FP_NAN)
1922+
{
1923+
return_nan = issignaling(lhs) ? nan_conversion(lhs) : lhs;
1924+
}
19081925
else
19091926
{
19101927
return_nan = issignaling(rhs) ? nan_conversion(rhs) : rhs;
@@ -1956,8 +1973,9 @@ constexpr auto div_impl(const decimal32_t lhs, const decimal32_t rhs, decimal32_
19561973
q = sign ? -zero : zero;
19571974
r = lhs;
19581975
return;
1959-
default:
1960-
static_cast<void>(rhs);
1976+
default:
1977+
static_cast<void>(rhs);
1978+
}
19611979
}
19621980
#else
19631981
static_cast<void>(r);

0 commit comments

Comments
 (0)