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
1 change: 1 addition & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
git submodule update --init libs/predef
git submodule update --init libs/static_assert
git submodule update --init libs/test
git submodule update --init libs/random
./bootstrap.sh
./b2 headers
- name: gcc-gcov-native
Expand Down
13 changes: 11 additions & 2 deletions include/boost/decimal/decimal128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ BOOST_DECIMAL_EXPORT class decimal128 final
explicit constexpr operator std::bfloat16_t() const noexcept;
#endif

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal128>), bool> = true>
constexpr operator Decimal() const noexcept;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal128>), bool> = true>
explicit constexpr operator Decimal() const noexcept;

// cmath functions that are easier as friends
Expand Down Expand Up @@ -1112,7 +1115,13 @@ constexpr decimal128::operator std::bfloat16_t() const noexcept
}
#endif

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal128>), bool>>
constexpr decimal128::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
}

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal128>), bool>>
constexpr decimal128::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
Expand Down
3 changes: 2 additions & 1 deletion include/boost/decimal/decimal32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ BOOST_DECIMAL_EXPORT class decimal32 final // NOLINT(cppcoreguidelines-special-m
explicit constexpr operator detail::uint128_t() const noexcept;
#endif

// We allow implict promotions to and decimal type with greater or equal precision (e.g. decimal32_fast)
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
explicit constexpr operator Decimal() const noexcept;
constexpr operator Decimal() const noexcept;

// 3.2.5 initialization from coefficient and exponent:
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
Expand Down
16 changes: 13 additions & 3 deletions include/boost/decimal/decimal32_fast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/decimal/detail/div_impl.hpp>
#include <boost/decimal/detail/promote_significand.hpp>
#include <boost/decimal/detail/ryu/ryu_generic_128.hpp>
#include <boost/decimal/detail/promotion.hpp>

#ifndef BOOST_DECIMAL_BUILD_MODULE
#include <limits>
Expand Down Expand Up @@ -112,7 +113,7 @@ BOOST_DECIMAL_EXPORT class decimal32_fast final
BOOST_DECIMAL_REQUIRES_RETURN(detail::is_decimal_floating_point_v, DecimalType, std::uint32_t);

public:
constexpr decimal32_fast() noexcept {}
constexpr decimal32_fast() noexcept = default;

template <typename T1, typename T2, std::enable_if_t<detail::is_integral_v<T1> && detail::is_integral_v<T2>, bool> = true>
constexpr decimal32_fast(T1 coeff, T2 exp, bool sign = false) noexcept;
Expand Down Expand Up @@ -319,7 +320,10 @@ BOOST_DECIMAL_EXPORT class decimal32_fast final


// Conversion to other decimal type
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal32_fast>), bool> = true>
constexpr operator Decimal() const noexcept;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal32_fast>), bool> = true>
explicit constexpr operator Decimal() const noexcept;

friend constexpr auto direct_init(std::uint_fast32_t significand, std::uint_fast8_t exponent, bool sign) noexcept -> decimal32_fast;
Expand Down Expand Up @@ -1341,7 +1345,13 @@ constexpr decimal32_fast::operator std::bfloat16_t() const noexcept
}
#endif

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal32_fast>), bool>>
constexpr decimal32_fast::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
}

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal32_fast>), bool>>
constexpr decimal32_fast::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
Expand Down
13 changes: 11 additions & 2 deletions include/boost/decimal/decimal64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ BOOST_DECIMAL_EXPORT class decimal64 final
#endif


template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
// Conversion to other decimal type
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal64>), bool> = true>
constexpr operator Decimal() const noexcept;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal64>), bool> = true>
explicit constexpr operator Decimal() const noexcept;

// 3.2.6 Conversion to floating-point type
Expand Down Expand Up @@ -951,8 +955,13 @@ constexpr decimal64::operator detail::uint128_t() const noexcept

#endif

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal64>), bool>>
constexpr decimal64::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
}

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal64>), bool>>
constexpr decimal64::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
Expand Down
15 changes: 13 additions & 2 deletions include/boost/decimal/decimal64_fast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <boost/decimal/detail/div_impl.hpp>
#include <boost/decimal/detail/promote_significand.hpp>
#include <boost/decimal/detail/ryu/ryu_generic_128.hpp>
#include <boost/decimal/detail/promotion.hpp>

#ifndef BOOST_DECIMAL_BUILD_MODULE

Expand Down Expand Up @@ -267,7 +268,11 @@ BOOST_DECIMAL_EXPORT class decimal64_fast final
explicit constexpr operator std::bfloat16_t() const noexcept;
#endif

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool> = true>
// Conversion to other decimal type
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal64_fast>), bool> = true>
constexpr operator Decimal() const noexcept;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal64_fast>), bool> = true>
explicit constexpr operator Decimal() const noexcept;

// Unary Operators
Expand Down Expand Up @@ -930,7 +935,13 @@ constexpr decimal64_fast::operator std::bfloat16_t() const noexcept
}
#endif

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal>, bool>>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> > detail::impl::decimal_val_v<decimal64_fast>), bool>>
constexpr decimal64_fast::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
}

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, std::enable_if_t<detail::is_decimal_floating_point_v<Decimal> && (detail::impl::decimal_val_v<Decimal> <= detail::impl::decimal_val_v<decimal64_fast>), bool>>
constexpr decimal64_fast::operator Decimal() const noexcept
{
return to_decimal<Decimal>(*this);
Expand Down
6 changes: 6 additions & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ run test_git_issue_266.cpp ;
run test_git_issue_271.cpp ;
run test_hash.cpp ;
run test_hermite.cpp ;
compile-fail test_illegal_decimal32_fast_implicit_conversions.cpp ;
compile-fail test_illegal_decimal32_implicit_conversions.cpp ;
compile-fail test_illegal_decimal64_fast_implicit_conversions.cpp ;
compile-fail test_illegal_decimal64_implicit_conversions.cpp ;
compile-fail test_illegal_decimal128_implicit_conversions.cpp ;
run test_implicit_integral_conversion.cpp ;
run test_laguerre.cpp ;
run test_legal_implicit_conversions.cpp ;
run test_legendre.cpp ;
run test_literals.cpp ;
run test_limits.cpp ;
Expand Down
20 changes: 13 additions & 7 deletions test/cover/make_gcov_02_files.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

FILES_PRJ := $(basename $(wildcard $(PATH_SRC)/*.cpp))

FILES_EXCLUDE := $(PATH_SRC)/concepts_test.cpp \
$(PATH_SRC)/link_1.cpp \
$(PATH_SRC)/link_2.cpp \
$(PATH_SRC)/link_3.cpp \
$(PATH_SRC)/test_bad_evaluation_method.cpp \
$(PATH_SRC)/test_explicit_floats.cpp \
$(PATH_SRC)/test_from_chars.cpp
FILES_EXCLUDE := $(PATH_SRC)/concepts_test.cpp \
$(PATH_SRC)/link_1.cpp \
$(PATH_SRC)/link_2.cpp \
$(PATH_SRC)/link_3.cpp \
$(PATH_SRC)/test_bad_evaluation_method.cpp \
$(PATH_SRC)/test_explicit_floats.cpp \
$(PATH_SRC)/test_from_chars.cpp \
$(PATH_SRC)/test_illegal_decimal32_fast_implicit_conversions.cpp \
$(PATH_SRC)/test_illegal_decimal32_implicit_conversions.cpp \
$(PATH_SRC)/test_illegal_decimal64_fast_implicit_conversions.cpp \
$(PATH_SRC)/test_illegal_decimal64_implicit_conversions.cpp \
$(PATH_SRC)/test_illegal_decimal128_implicit_conversions.cpp \


FILES_EXCLUDE := $(basename $(FILES_EXCLUDE))

Expand Down
22 changes: 22 additions & 0 deletions test/test_illegal_decimal128_implicit_conversions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

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

template <typename From, typename To>
void test_implicit()
{
const From from_val {2, 1};
const To to_val = from_val;

BOOST_TEST_EQ(from_val, to_val);
}

int main()
{
test_implicit<boost::decimal::decimal128_fast, boost::decimal::decimal128>();

return boost::report_errors();
}
25 changes: 25 additions & 0 deletions test/test_illegal_decimal32_fast_implicit_conversions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

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

template <typename From, typename To>
void test_implicit()
{
const From from_val {2, 1};
const To to_val = from_val;

BOOST_TEST_EQ(from_val, to_val);
}

int main()
{
test_implicit<boost::decimal::decimal64, boost::decimal::decimal32_fast>();
test_implicit<boost::decimal::decimal64_fast, boost::decimal::decimal32_fast>();
test_implicit<boost::decimal::decimal128, boost::decimal::decimal32_fast>();
test_implicit<boost::decimal::decimal128_fast, boost::decimal::decimal32_fast>();

return boost::report_errors();
}
26 changes: 26 additions & 0 deletions test/test_illegal_decimal32_implicit_conversions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

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

template <typename From, typename To>
void test_implicit()
{
const From from_val {2, 1};
const To to_val = from_val;

BOOST_TEST_EQ(from_val, to_val);
}

int main()
{
test_implicit<boost::decimal::decimal32_fast, boost::decimal::decimal32>();
test_implicit<boost::decimal::decimal64, boost::decimal::decimal32>();
test_implicit<boost::decimal::decimal64_fast, boost::decimal::decimal32>();
test_implicit<boost::decimal::decimal128, boost::decimal::decimal32>();
test_implicit<boost::decimal::decimal128_fast, boost::decimal::decimal32>();

return boost::report_errors();
}
23 changes: 23 additions & 0 deletions test/test_illegal_decimal64_fast_implicit_conversions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

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

template <typename From, typename To>
void test_implicit()
{
const From from_val {2, 1};
const To to_val = from_val;

BOOST_TEST_EQ(from_val, to_val);
}

int main()
{
test_implicit<boost::decimal::decimal128, boost::decimal::decimal64_fast>();
test_implicit<boost::decimal::decimal128_fast, boost::decimal::decimal64_fast>();

return boost::report_errors();
}
24 changes: 24 additions & 0 deletions test/test_illegal_decimal64_implicit_conversions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

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

template <typename From, typename To>
void test_implicit()
{
const From from_val {2, 1};
const To to_val = from_val;

BOOST_TEST_EQ(from_val, to_val);
}

int main()
{
test_implicit<boost::decimal::decimal64_fast, boost::decimal::decimal64>();
test_implicit<boost::decimal::decimal128, boost::decimal::decimal64>();
test_implicit<boost::decimal::decimal128_fast, boost::decimal::decimal64>();

return boost::report_errors();
}
Loading
Loading