Skip to content

Commit 2db0a50

Browse files
committed
Merge branch 'develop' into t_gamma_bama_jama
2 parents 46b73aa + 6b1ba1c commit 2db0a50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+990
-337
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ jobs:
414414
B2_ARGS+=("address-model=${{matrix.address_model}}")
415415
fi
416416
B2_ARGS+=("libs/$LIBRARY/test")
417-
./b2 "${B2_ARGS[@]}"
417+
./b2 "${B2_ARGS[@]}" cxxflags="-Wall -Wextra -Werror"
418418
419419
windows:
420420
strategy:

include/boost/decimal.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
#ifndef BOOST_DECIMAL_HPP
66
#define BOOST_DECIMAL_HPP
77

8+
// Clang-Cl likes to throw warnings everywhere for this
9+
// disable at the global level
10+
#if defined(__clang__) && !defined(__GNUC__)
11+
# pragma clang diagnostic push
12+
# pragma clang diagnostic ignored "-Wc++98-compat"
13+
# pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
14+
#endif
15+
816
#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
917
#include <boost/decimal/decimal32.hpp>
1018
#include <boost/decimal/decimal64.hpp>
@@ -17,5 +25,10 @@
1725
#include <boost/decimal/cfloat.hpp>
1826
#include <boost/decimal/charconv.hpp>
1927
#include <boost/decimal/type_traits.hpp>
28+
#include <boost/decimal/detail/io.hpp>
29+
30+
#if defined(__clang__) && !defined(__GNUC__)
31+
# pragma clang diagnostic pop
32+
#endif
2033

2134
#endif // BOOST_DECIMAL_HPP

include/boost/decimal/charconv.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_nonfinite(char* first, char* last, const T
144144

145145
if (precision != -1 && precision != 1)
146146
{
147-
boost::decimal::detail::memset(first, '0', precision - 1);
147+
boost::decimal::detail::memset(first, '0', static_cast<std::size_t>(precision - 1));
148148
first += precision - 1;
149149
}
150150
}
@@ -171,12 +171,12 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_nonfinite(char* first, char* last, const T
171171
}
172172
else if (buffer_len > 2 + precision)
173173
{
174-
boost::decimal::detail::memcpy(first, "0.0", 3);
174+
boost::decimal::detail::memcpy(first, "0.0", 3U);
175175
first += 3U;
176176

177177
if (precision > 1)
178178
{
179-
boost::decimal::detail::memset(first, '0', precision - 1);
179+
boost::decimal::detail::memset(first, '0', static_cast<std::size_t>(precision - 1));
180180
first += precision - 1;
181181
}
182182

@@ -191,6 +191,11 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_nonfinite(char* first, char* last, const T
191191
boost::decimal::detail::memcpy(first, "nan(snan)", 9U);
192192
return {first + 9U, std::errc()};
193193
}
194+
else if (signbit(value) && buffer_len >= 9)
195+
{
196+
boost::decimal::detail::memcpy(first, "nan(ind)", 8U);
197+
return {first + 8U, std::errc()};
198+
}
194199
else if (buffer_len >= 3)
195200
{
196201
boost::decimal::detail::memcpy(first, "nan", 3U);
@@ -315,7 +320,7 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_scientific_impl(char* first, char* last, c
315320
}
316321

317322
// Always give 2 digits in the exp (ex. 2.0e+09)
318-
if (abs_exp < 9)
323+
if (abs_exp <= 9)
319324
{
320325
*first++ = '0';
321326
}
@@ -465,14 +470,13 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_fixed_impl(char* first, char* last, const
465470
{
466471
boost::decimal::detail::memmove(r.ptr + exponent + 1, r.ptr + exponent,
467472
static_cast<std::size_t>(-exponent));
468-
boost::decimal::detail::memset(r.ptr + exponent, '.', 1);
473+
boost::decimal::detail::memset(r.ptr + exponent, '.', 1U);
469474
++r.ptr;
470475
}
471-
472-
while (fmod(abs_value, static_cast<TargetDecimalType>(10)) == 0)
476+
else if (exponent >= 1)
473477
{
474-
*r.ptr++ = '0';
475-
abs_value /= 10;
478+
boost::decimal::detail::memset(r.ptr, '0', static_cast<std::size_t>(exponent));
479+
r.ptr += exponent;
476480
}
477481
}
478482
else if (!append_leading_zeros)
@@ -649,7 +653,7 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_hex_impl(char* first, char* last, const Ta
649653
*first++ = '0';
650654
}
651655

652-
return to_chars_integer_impl<std::uint32_t, std::uint32_t>(first, last, std::abs(exp), 10);
656+
return to_chars_integer_impl<std::uint32_t, std::uint32_t>(first, last, static_cast<std::uint32_t>(std::abs(exp)), 10);
653657
}
654658

655659
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetDecimalType>

include/boost/decimal/decimal128.hpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <boost/decimal/detail/to_float.hpp>
2727
#include <boost/decimal/detail/to_decimal.hpp>
2828
#include <boost/decimal/detail/promotion.hpp>
29-
#include <boost/decimal/detail/io.hpp>
3029
#include <boost/decimal/detail/check_non_finite.hpp>
3130
#include <boost/decimal/detail/shrink_significand.hpp>
3231
#include <boost/decimal/detail/cmath/isfinite.hpp>
@@ -474,16 +473,6 @@ class decimal128 final
474473
#endif
475474

476475
#if !defined(BOOST_DECIMAL_DISABLE_IOSTREAM)
477-
// 3.2.10 Formatted input:
478-
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
479-
friend auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)
480-
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_istream<charT, traits>&>;
481-
482-
// 3.2.11 Formatted output:
483-
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
484-
friend auto operator<<(std::basic_ostream<charT, traits>& os, const DecimalType& d)
485-
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_ostream<charT, traits>&>;
486-
487476
friend inline std::string bit_string(decimal128 rhs) noexcept;
488477
#endif
489478

@@ -677,6 +666,11 @@ constexpr auto decimal128::edit_sign(bool sign) noexcept -> void
677666
}
678667
}
679668

669+
#if defined(__GNUC__) && __GNUC__ >= 6
670+
# pragma GCC diagnostic push
671+
# pragma GCC diagnostic ignored "-Wduplicated-branches"
672+
#endif
673+
680674
// TODO(mborland): Rather than doing bitwise operations on the whole uint128 we should
681675
// be able to only operate on the affected word
682676
//
@@ -834,6 +828,18 @@ constexpr decimal128::decimal128(T1 coeff, T2 exp, bool sign) noexcept
834828
}
835829
}
836830

831+
#if defined(__GNUC__) && __GNUC__ >= 6
832+
# pragma GCC diagnostic pop
833+
#endif
834+
835+
#if defined(__clang__)
836+
# pragma clang diagnostic push
837+
# pragma clang diagnostic ignored "-Wfloat-equal"
838+
#elif defined(__GNUC__)
839+
# pragma GCC diagnostic push
840+
# pragma GCC diagnostic ignored "-Wfloat-equal"
841+
#endif
842+
837843
template <typename Float, std::enable_if_t<detail::is_floating_point_v<Float>, bool>>
838844
BOOST_DECIMAL_CXX20_CONSTEXPR decimal128::decimal128(Float val) noexcept
839845
{
@@ -866,6 +872,12 @@ BOOST_DECIMAL_CXX20_CONSTEXPR decimal128::decimal128(Float val) noexcept
866872
}
867873
}
868874

875+
#if defined(__clang__)
876+
# pragma clang diagnostic pop
877+
#elif defined(__GNUC__)
878+
# pragma GCC diagnostic pop
879+
#endif
880+
869881
template <typename Float, std::enable_if_t<detail::is_floating_point_v<Float>, bool>>
870882
BOOST_DECIMAL_CXX20_CONSTEXPR auto decimal128::operator=(const Float& val) noexcept -> decimal128&
871883
{

include/boost/decimal/decimal32.hpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <boost/decimal/detail/to_float.hpp>
2626
#include <boost/decimal/detail/to_decimal.hpp>
2727
#include <boost/decimal/detail/promotion.hpp>
28-
#include <boost/decimal/detail/io.hpp>
2928
#include <boost/decimal/detail/check_non_finite.hpp>
3029
#include <boost/decimal/detail/shrink_significand.hpp>
3130
#include <boost/decimal/detail/cmath/isfinite.hpp>
@@ -458,18 +457,6 @@ class decimal32 final // NOLINT(cppcoreguidelines-special-member-functions,hicpp
458457
friend constexpr auto operator<=>(Integer lhs, decimal32 rhs) noexcept -> std::enable_if_t<detail::is_integral_v<Integer>, std::partial_ordering>;
459458
#endif
460459

461-
#if !defined(BOOST_DECIMAL_DISABLE_IOSTREAM)
462-
// 3.2.10 Formatted input:
463-
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
464-
friend auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)
465-
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_istream<charT, traits>&>;
466-
467-
// 3.2.11 Formatted output:
468-
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
469-
friend auto operator<<(std::basic_ostream<charT, traits>& os, const DecimalType& d)
470-
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_ostream<charT, traits>&>;
471-
#endif
472-
473460
// Bitwise operators
474461
friend constexpr auto operator&(decimal32 lhs, decimal32 rhs) noexcept -> decimal32;
475462

@@ -567,6 +554,11 @@ class decimal32 final // NOLINT(cppcoreguidelines-special-member-functions,hicpp
567554
# pragma GCC diagnostic pop
568555
#endif
569556

557+
#if defined(__GNUC__) && __GNUC__ >= 6
558+
# pragma GCC diagnostic push
559+
# pragma GCC diagnostic ignored "-Wduplicated-branches"
560+
#endif
561+
570562
template <typename T, typename T2, std::enable_if_t<detail::is_integral_v<T>, bool>>
571563
constexpr decimal32::decimal32(T coeff, T2 exp, bool sign) noexcept // NOLINT(readability-function-cognitive-complexity,misc-no-recursion)
572564
{
@@ -608,7 +600,7 @@ constexpr decimal32::decimal32(T coeff, T2 exp, bool sign) noexcept // NOLINT(re
608600
// Round as required
609601
if (reduced)
610602
{
611-
exp += detail::fenv_round(unsigned_coeff, isneg);
603+
exp += static_cast<T2>(detail::fenv_round(unsigned_coeff, isneg));
612604
}
613605

614606
auto reduced_coeff {static_cast<std::uint32_t>(unsigned_coeff)};
@@ -730,6 +722,10 @@ constexpr decimal32::decimal32(T coeff, T2 exp, bool sign) noexcept // NOLINT(re
730722
}
731723
}
732724

725+
#if defined(__GNUC__) && __GNUC__ >= 6
726+
# pragma GCC diagnostic pop
727+
#endif
728+
733729
constexpr auto from_bits(std::uint32_t bits) noexcept -> decimal32
734730
{
735731
decimal32 result;
@@ -1540,6 +1536,14 @@ constexpr auto decimal32::edit_sign(bool sign) noexcept -> void
15401536
}
15411537
}
15421538

1539+
#if defined(__clang__)
1540+
# pragma clang diagnostic push
1541+
# pragma clang diagnostic ignored "-Wfloat-equal"
1542+
#elif defined(__GNUC__)
1543+
# pragma GCC diagnostic push
1544+
# pragma GCC diagnostic ignored "-Wfloat-equal"
1545+
#endif
1546+
15431547
template <typename Float, std::enable_if_t<detail::is_floating_point_v<Float>, bool>>
15441548
BOOST_DECIMAL_CXX20_CONSTEXPR decimal32::decimal32(Float val) noexcept
15451549
{
@@ -1572,6 +1576,12 @@ BOOST_DECIMAL_CXX20_CONSTEXPR decimal32::decimal32(Float val) noexcept
15721576
}
15731577
}
15741578

1579+
#if defined(__clang__)
1580+
# pragma clang diagnostic pop
1581+
#elif defined(__GNUC__)
1582+
# pragma GCC diagnostic pop
1583+
#endif
1584+
15751585
template <typename Float, std::enable_if_t<detail::is_floating_point_v<Float>, bool>>
15761586
BOOST_DECIMAL_CXX20_CONSTEXPR auto decimal32::operator=(const Float& val) noexcept -> decimal32&
15771587
{
@@ -1713,7 +1723,7 @@ constexpr auto mul_impl(T lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
17131723

17141724
if (sig_dig > 9)
17151725
{
1716-
res_sig /= detail::powers_of_10[sig_dig - 9];
1726+
res_sig /= detail::pow10(static_cast<std::uint64_t>(sig_dig - 9));
17171727
res_exp += sig_dig - 9;
17181728
}
17191729

@@ -1825,7 +1835,7 @@ constexpr auto generic_div_impl(detail::decimal32_components lhs, detail::decima
18251835

18261836
if (sig_dig > std::numeric_limits<std::uint32_t>::digits10)
18271837
{
1828-
res_sig /= detail::powers_of_10[sig_dig - std::numeric_limits<std::uint32_t>::digits10];
1838+
res_sig /= detail::pow10(static_cast<std::uint64_t>(sig_dig - std::numeric_limits<std::uint32_t>::digits10));
18291839
res_exp += sig_dig - std::numeric_limits<std::uint32_t>::digits10;
18301840
}
18311841

include/boost/decimal/decimal64.hpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <boost/decimal/detail/to_float.hpp>
2626
#include <boost/decimal/detail/to_decimal.hpp>
2727
#include <boost/decimal/detail/promotion.hpp>
28-
#include <boost/decimal/detail/io.hpp>
2928
#include <boost/decimal/detail/comparison.hpp>
3029
#include <boost/decimal/detail/mixed_decimal_arithmetic.hpp>
3130
#include <boost/decimal/detail/check_non_finite.hpp>
@@ -464,18 +463,6 @@ class decimal64 final
464463
friend constexpr auto operator<=>(Integer lhs, decimal64 rhs) noexcept -> std::enable_if_t<detail::is_integral_v<Integer>, std::partial_ordering>;
465464
#endif
466465

467-
#if !defined(BOOST_DECIMAL_DISABLE_IOSTREAM)
468-
// 3.2.10 Formatted input:
469-
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
470-
friend auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)
471-
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_istream<charT, traits>&>;
472-
473-
// 3.2.11 Formatted output:
474-
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
475-
friend auto operator<<(std::basic_ostream<charT, traits>& os, const DecimalType& d)
476-
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_ostream<charT, traits>&>;
477-
#endif
478-
479466
// 3.6.4 Same Quantum
480467
friend constexpr auto samequantumd64(decimal64 lhs, decimal64 rhs) noexcept -> bool;
481468

@@ -568,6 +555,11 @@ constexpr auto to_bits(decimal64 rhs) noexcept -> std::uint64_t
568555
return rhs.bits_;
569556
}
570557

558+
#if defined(__GNUC__) && __GNUC__ >= 6
559+
# pragma GCC diagnostic push
560+
# pragma GCC diagnostic ignored "-Wduplicated-branches"
561+
#endif
562+
571563
// 3.2.5 initialization from coefficient and exponent:
572564
template <typename T1, typename T2, std::enable_if_t<detail::is_integral_v<T1>, bool>>
573565
constexpr decimal64::decimal64(T1 coeff, T2 exp, bool sign) noexcept
@@ -721,6 +713,18 @@ constexpr decimal64::decimal64(T1 coeff, T2 exp, bool sign) noexcept
721713
}
722714
}
723715

716+
#if defined(__GNUC__) && __GNUC__ >= 6
717+
# pragma GCC diagnostic pop
718+
#endif
719+
720+
#if defined(__clang__)
721+
# pragma clang diagnostic push
722+
# pragma clang diagnostic ignored "-Wfloat-equal"
723+
#elif defined(__GNUC__)
724+
# pragma GCC diagnostic push
725+
# pragma GCC diagnostic ignored "-Wfloat-equal"
726+
#endif
727+
724728
template <typename Float, std::enable_if_t<detail::is_floating_point_v<Float>, bool>>
725729
BOOST_DECIMAL_CXX20_CONSTEXPR decimal64::decimal64(Float val) noexcept
726730
{
@@ -753,6 +757,12 @@ BOOST_DECIMAL_CXX20_CONSTEXPR decimal64::decimal64(Float val) noexcept
753757
}
754758
}
755759

760+
#if defined(__clang__)
761+
# pragma clang diagnostic pop
762+
#elif defined(__GNUC__)
763+
# pragma GCC diagnostic pop
764+
#endif
765+
756766
template <typename Float, std::enable_if_t<detail::is_floating_point_v<Float>, bool>>
757767
BOOST_DECIMAL_CXX20_CONSTEXPR auto decimal64::operator=(const Float& val) noexcept -> decimal64&
758768
{
@@ -1210,7 +1220,7 @@ constexpr auto d64_mul_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
12101220

12111221
if (sig_dig > std::numeric_limits<std::uint64_t>::digits10)
12121222
{
1213-
res_sig /= detail::powers_of_10[sig_dig - std::numeric_limits<std::uint64_t>::digits10];
1223+
res_sig /= static_cast<unsigned_int128_type>(detail::pow10(static_cast<std::uint64_t>(sig_dig - std::numeric_limits<std::uint64_t>::digits10)));
12141224
res_exp += sig_dig - std::numeric_limits<std::uint64_t>::digits10;
12151225
}
12161226

@@ -1253,7 +1263,7 @@ constexpr auto d64_generic_div_impl(detail::decimal64_components lhs, detail::de
12531263

12541264
if (sig_dig > std::numeric_limits<std::uint64_t>::digits10)
12551265
{
1256-
res_sig /= detail::powers_of_10[sig_dig - std::numeric_limits<std::uint64_t>::digits10];
1266+
res_sig /= static_cast<unsigned_int128_type>(detail::pow10(static_cast<std::uint64_t>(sig_dig - std::numeric_limits<std::uint64_t>::digits10)));
12571267
res_exp += sig_dig - std::numeric_limits<std::uint64_t>::digits10;
12581268
}
12591269

include/boost/decimal/detail/apply_sign.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <typename Integer, typename Unsigned_Integer = detail::make_unsigned_t<
3434
std::enable_if_t<detail::is_signed_v<Integer>, bool> = true>
3535
constexpr auto make_positive_unsigned(Integer val) noexcept -> Unsigned_Integer
3636
{
37-
return static_cast<Unsigned_Integer>(val < static_cast<std::int8_t>(0) ? apply_sign(val) : val);
37+
return static_cast<Unsigned_Integer>(val < static_cast<std::int8_t>(0) ? apply_sign(val) : static_cast<Unsigned_Integer>(val));
3838
}
3939

4040
template <typename Unsigned_Integer, std::enable_if_t<!detail::is_signed_v<Unsigned_Integer>, bool> = true>

include/boost/decimal/detail/cmath/ceil.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ constexpr auto ceil BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T val) noexcept
6868
}
6969
new_sig *= 10;
7070

71-
return {new_sig, exp_ptr + decimal_digits - 1, is_neg};
71+
return {new_sig, exp_ptr + static_cast<int>(decimal_digits) - 1, is_neg};
7272
}
7373

7474
} // namespace decimal

include/boost/decimal/detail/cmath/cos.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ constexpr auto cos(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating
6464
int k {};
6565
auto r { remquo(x, my_pi_half, &k) };
6666

67-
const auto n = static_cast<unsigned>(k % 4U);
67+
const auto n = static_cast<unsigned>(k % 4);
6868

6969
switch(n)
7070
{

0 commit comments

Comments
 (0)