Skip to content

Commit 2a66705

Browse files
committed
Implement support for 7.2.b
1 parent 77aaa67 commit 2a66705

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

include/boost/decimal/decimal128_t.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,19 +1658,21 @@ constexpr auto operator*(const decimal128_t& lhs, const decimal128_t& rhs) noexc
16581658
#ifndef BOOST_DECIMAL_FAST_MATH
16591659
if (not_finite(lhs) || not_finite(rhs))
16601660
{
1661+
if ((isinf(lhs) && rhs == 0) || (isinf(rhs) && lhs == 0))
1662+
{
1663+
return from_bits(detail::d128_nan_mask);
1664+
}
1665+
16611666
return detail::check_non_finite(lhs, rhs);
16621667
}
16631668
#endif
16641669

1665-
const auto lhs_sig {lhs.full_significand()};
1666-
const auto lhs_exp {lhs.biased_exponent()};
1667-
1668-
const auto rhs_sig {rhs.full_significand()};
1669-
const auto rhs_exp {rhs.biased_exponent()};
1670+
const auto lhs_components {lhs.to_components()};
1671+
const auto rhs_components {rhs.to_components()};
16701672

16711673
return detail::d128_mul_impl<decimal128_t>(
1672-
lhs_sig, lhs_exp, lhs.isneg(),
1673-
rhs_sig, rhs_exp, rhs.isneg());
1674+
lhs_components.sig, lhs_components.exp, lhs_components.sign,
1675+
rhs_components.sig, rhs_components.exp, rhs_components.sign);
16741676
}
16751677

16761678
template <typename Integer>

include/boost/decimal/decimal32_t.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,11 @@ constexpr auto operator*(const decimal32_t lhs, const decimal32_t rhs) noexcept
16571657
#ifndef BOOST_DECIMAL_FAST_MATH
16581658
if (!isfinite(lhs) || !isfinite(rhs))
16591659
{
1660+
if ((isinf(lhs) && rhs == 0) || (isinf(rhs) && lhs == 0))
1661+
{
1662+
return from_bits(detail::d32_nan_mask);
1663+
}
1664+
16601665
return detail::check_non_finite(lhs, rhs);
16611666
}
16621667
#endif

include/boost/decimal/decimal64_t.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,16 +1355,19 @@ constexpr auto operator*(const decimal64_t lhs, const decimal64_t rhs) noexcept
13551355
#ifndef BOOST_DECIMAL_FAST_MATH
13561356
if (not_finite(lhs) || not_finite(rhs))
13571357
{
1358+
if ((isinf(lhs) && rhs == 0) || (isinf(rhs) && lhs == 0))
1359+
{
1360+
return from_bits(detail::d64_nan_mask);
1361+
}
1362+
13581363
return detail::check_non_finite(lhs, rhs);
13591364
}
13601365
#endif
13611366

1362-
auto lhs_components {lhs.to_components()};
1363-
detail::expand_significand<decimal64_t>(lhs_components.sig, lhs_components.exp);
1364-
auto rhs_components {rhs.to_components()};
1365-
detail::expand_significand<decimal64_t>(rhs_components.sig, rhs_components.exp);
1367+
const auto lhs_components {lhs.to_components()};
1368+
const auto rhs_components {rhs.to_components()};
13661369

1367-
return detail::d64_mul_impl<decimal64_t>(lhs_components, rhs_components);
1370+
return detail::mul_impl<decimal64_t>(lhs_components, rhs_components);
13681371
}
13691372

13701373
template <typename Integer>

include/boost/decimal/decimal_fast128_t.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,11 @@ constexpr auto operator*(const decimal_fast128_t& lhs, const decimal_fast128_t&
10361036
#ifndef BOOST_DECIMAL_FAST_MATH
10371037
if (not_finite(lhs) || not_finite(rhs))
10381038
{
1039+
if ((isinf(lhs) && rhs == 0) || (isinf(rhs) && lhs == 0))
1040+
{
1041+
return direct_init_d128(detail::d128_fast_qnan, 0, false);
1042+
}
1043+
10391044
return detail::check_non_finite(lhs, rhs);
10401045
}
10411046
#endif

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,11 @@ constexpr auto operator*(const decimal_fast32_t lhs, const decimal_fast32_t rhs)
10061006
#ifndef BOOST_DECIMAL_FAST_MATH
10071007
if (!isfinite(lhs) || !isfinite(rhs))
10081008
{
1009+
if ((isinf(lhs) && rhs == 0) || (isinf(rhs) && lhs == 0))
1010+
{
1011+
return direct_init(detail::d32_fast_qnan, UINT8_C(0));
1012+
}
1013+
10091014
return detail::check_non_finite(lhs, rhs);
10101015
}
10111016
#endif

include/boost/decimal/decimal_fast64_t.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@ constexpr auto operator*(const decimal_fast64_t lhs, const decimal_fast64_t rhs)
11291129
#ifndef BOOST_DECIMAL_FAST_MATH
11301130
if (not_finite(lhs) || not_finite(rhs))
11311131
{
1132+
if ((isinf(lhs) && rhs == 0) || (isinf(rhs) && lhs == 0))
1133+
{
1134+
return direct_init_d64(detail::d64_fast_qnan, 0, false);
1135+
}
1136+
11321137
return detail::check_non_finite(lhs, rhs);
11331138
}
11341139
#endif

test/github_issue_1107.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ void test_mul()
2121
const T a {dist(rng) * 0};
2222
const T b {dist(rng) * std::numeric_limits<T>::infinity()};
2323

24+
BOOST_TEST(a == 0);
25+
BOOST_TEST(isinf(b));
26+
2427
BOOST_TEST(isnan(a * b));
2528
BOOST_TEST(isnan(b * a));
2629
}
@@ -65,7 +68,7 @@ int main()
6568
test_mul<decimal_fast32_t>();
6669
test_mul<decimal_fast64_t>();
6770
test_mul<decimal_fast128_t>();
68-
71+
6972
test_sqrt<decimal32_t>();
7073
test_sqrt<decimal64_t>();
7174
test_sqrt<decimal128_t>();

0 commit comments

Comments
 (0)