Skip to content

Commit 3046844

Browse files
committed
Fix processing of return nan value
1 parent da6115a commit 3046844

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

include/boost/decimal/decimal32_t.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,8 +1896,20 @@ constexpr auto div_impl(const decimal32_t lhs, const decimal32_t rhs, decimal32_
18961896

18971897
if (lhs_fp == FP_NAN || rhs_fp == FP_NAN)
18981898
{
1899-
q = nan;
1900-
r = nan;
1899+
// Operations on an SNAN return a QNAN with the same payload
1900+
decimal32_t return_nan {};
1901+
if (lhs_fp == FP_NAN)
1902+
{
1903+
return_nan = issignaling(lhs) ? nan_conversion(lhs) : lhs;
1904+
}
1905+
else
1906+
{
1907+
return_nan = issignaling(rhs) ? nan_conversion(rhs) : rhs;
1908+
}
1909+
1910+
q = return_nan;
1911+
r = return_nan;
1912+
19011913
return;
19021914
}
19031915

0 commit comments

Comments
 (0)