Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ constexpr auto operator/(const decimal128_t lhs, const Integer rhs) noexcept
case FP_NAN:
return issignaling(lhs) ? nan_conversion(lhs) : lhs;
case FP_INFINITE:
return lhs;
return sign ? -lhs : lhs;
case FP_ZERO:
return sign ? -zero : zero;
default:
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal32_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ constexpr auto operator/(const decimal32_t lhs, Integer rhs) noexcept
case FP_NAN:
return issignaling(lhs) ? nan_conversion(lhs) : lhs;
case FP_INFINITE:
return lhs;
return sign ? -lhs : lhs;
case FP_ZERO:
return sign ? -zero : zero;
default:
Expand Down
6 changes: 3 additions & 3 deletions include/boost/decimal/decimal64_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ constexpr auto d64_div_impl(const decimal64_t lhs, const decimal64_t rhs, decima
switch (lhs_fp)
{
case FP_INFINITE:
if (lhs_fp == FP_INFINITE)
if (rhs_fp == FP_INFINITE)
{
q = nan;
r = nan;
Expand Down Expand Up @@ -1604,7 +1604,7 @@ constexpr auto d64_div_impl(const decimal64_t lhs, const decimal64_t rhs, decima
switch (rhs_fp)
{
case FP_ZERO:
q = inf;
q = sign ? -inf : inf;
r = zero;
return;
case FP_INFINITE:
Expand Down Expand Up @@ -1901,7 +1901,7 @@ constexpr auto operator/(const decimal64_t lhs, const Integer rhs) noexcept
case FP_NAN:
return issignaling(lhs) ? nan_conversion(lhs) : lhs;
case FP_INFINITE:
return lhs;
return sign ? -lhs : lhs;
case FP_ZERO:
return sign ? -zero : zero;
default:
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal_fast128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ constexpr auto operator/(const decimal_fast128_t& lhs, const Integer rhs) noexce
case FP_NAN:
return issignaling(lhs) ? nan_conversion(lhs) : lhs;;
case FP_INFINITE:
return lhs;
return sign ? -lhs : lhs;
case FP_ZERO:
return sign ? -zero : zero;
default:
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal_fast32_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ constexpr auto operator/(const decimal_fast32_t lhs, const Integer rhs) noexcept
case FP_NAN:
return issignaling(lhs) ? nan_conversion(lhs) : lhs;
case FP_INFINITE:
return lhs;
return sign ? -lhs : lhs;
case FP_ZERO:
return sign ? -zero : zero;
default:
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/decimal_fast64_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ constexpr auto operator/(const decimal_fast64_t lhs, const Integer rhs) noexcept
case FP_NAN:
return issignaling(lhs) ? nan_conversion(lhs) : lhs;;
case FP_INFINITE:
return lhs;
return sign ? -lhs : lhs;
case FP_ZERO:
return sign ? -zero : zero;
default:
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ run github_issue_1299.cpp ;
run github_issue_1302.cpp ;
run github_issue_1304.cpp ;
run github_issue_1306.cpp ;
run github_issue_1312.cpp ;

run link_1.cpp link_2.cpp link_3.cpp ;
run quick.cpp ;
Expand Down
37 changes: 37 additions & 0 deletions test/github_issue_1312.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2026 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
//
// See: https://github.com/cppalliance/decimal/issues/1312

#include <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>
#include <limits>

using namespace boost::decimal;

template <typename T>
void test()
{
constexpr T inf {std::numeric_limits<T>::infinity()};

BOOST_TEST(isnan(inf / -inf));
BOOST_TEST_EQ(inf / -1000, -inf);
BOOST_TEST_EQ(inf / -T{1000}, -inf);
BOOST_TEST_EQ(inf / 0, inf);
BOOST_TEST_EQ(inf / T{0}, inf);
BOOST_TEST_EQ(0 / inf, T{0});
}

int main()
{
test<decimal32_t>();
test<decimal64_t>();
test<decimal128_t>();

test<decimal_fast32_t>();
test<decimal_fast64_t>();
test<decimal_fast128_t>();

return boost::report_errors();
}
2 changes: 2 additions & 0 deletions test/random_decimal64_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ int main()

spot_mixed_division(4930, -24419);

BOOST_TEST_EQ(decimal64_t{"Inf"} / decimal64_t{-1000}, -std::numeric_limits<decimal64_t>::infinity());

return boost::report_errors();
}

Expand Down
Loading