Skip to content

Commit 3f106a4

Browse files
committed
Use new function to correct mixed type nan returns
1 parent 700931d commit 3f106a4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

include/boost/decimal/decimal32_t.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ constexpr auto operator+(const decimal32_t lhs, const Integer rhs) noexcept
10591059
#ifndef BOOST_DECIMAL_FAST_MATH
10601060
if (!isfinite(lhs))
10611061
{
1062-
return lhs;
1062+
return detail::check_non_finite(lhs);
10631063
}
10641064
#endif
10651065

@@ -1160,7 +1160,7 @@ constexpr auto operator-(const decimal32_t lhs, const Integer rhs) noexcept
11601160
#ifndef BOOST_DECIMAL_FAST_MATH
11611161
if (!isfinite(lhs))
11621162
{
1163-
return lhs;
1163+
return detail::check_non_finite(lhs);
11641164
}
11651165
#endif
11661166

@@ -1191,7 +1191,7 @@ constexpr auto operator-(const Integer lhs, const decimal32_t rhs) noexcept
11911191
#ifndef BOOST_DECIMAL_FAST_MATH
11921192
if (!isfinite(rhs))
11931193
{
1194-
return rhs;
1194+
return detail::check_non_finite(rhs);
11951195
}
11961196
#endif
11971197

@@ -1838,7 +1838,7 @@ constexpr auto operator*(const decimal32_t lhs, const Integer rhs) noexcept
18381838
#ifndef BOOST_DECIMAL_FAST_MATH
18391839
if (!isfinite(lhs))
18401840
{
1841-
return lhs;
1841+
return detail::check_non_finite(lhs);
18421842
}
18431843
#endif
18441844

@@ -2008,7 +2008,6 @@ constexpr auto operator/(const decimal32_t lhs, Integer rhs) noexcept
20082008
#ifndef BOOST_DECIMAL_FAST_MATH
20092009
// Check pre-conditions
20102010
constexpr decimal32_t zero {0, 0};
2011-
constexpr decimal32_t nan {boost::decimal::from_bits(boost::decimal::detail::d32_snan_mask)};
20122011
constexpr decimal32_t inf {boost::decimal::from_bits(boost::decimal::detail::d32_inf_mask)};
20132012

20142013
const bool sign {lhs.isneg() != (rhs < 0)};
@@ -2018,9 +2017,9 @@ constexpr auto operator/(const decimal32_t lhs, Integer rhs) noexcept
20182017
switch (lhs_fp)
20192018
{
20202019
case FP_NAN:
2021-
return nan;
2020+
return issignaling(lhs) ? nan_conversion(lhs) : lhs;
20222021
case FP_INFINITE:
2023-
return inf;
2022+
return lhs;
20242023
case FP_ZERO:
20252024
return sign ? -zero : zero;
20262025
default:
@@ -2057,7 +2056,6 @@ constexpr auto operator/(Integer lhs, const decimal32_t rhs) noexcept
20572056
#ifndef BOOST_DECIMAL_FAST_MATH
20582057
// Check pre-conditions
20592058
constexpr decimal32_t zero {0, 0};
2060-
constexpr decimal32_t nan {boost::decimal::from_bits(boost::decimal::detail::d32_snan_mask)};
20612059
constexpr decimal32_t inf {boost::decimal::from_bits(boost::decimal::detail::d32_inf_mask)};
20622060

20632061
const bool sign {(lhs < 0) != rhs.isneg()};
@@ -2066,7 +2064,7 @@ constexpr auto operator/(Integer lhs, const decimal32_t rhs) noexcept
20662064

20672065
if (rhs_fp == FP_NAN)
20682066
{
2069-
return nan;
2067+
return detail::check_non_finite(rhs);
20702068
}
20712069

20722070
switch (rhs_fp)

0 commit comments

Comments
 (0)