Skip to content

Commit 44bf2bf

Browse files
authored
Merge pull request #762 from cppalliance/rescale
Refactor rescale
2 parents defb2dc + 384155e commit 44bf2bf

File tree

10 files changed

+34
-1391
lines changed

10 files changed

+34
-1391
lines changed

doc/decimal/cmath.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,13 @@ constexpr boost::decimal::detail::uint128 frexpd128(decimal128 num, int* expptr)
459459
This function is very similar to https://en.cppreference.com/w/cpp/numeric/math/frexp[frexp], but returns the significand and an integral power of 10 since the `FLT_RADIX` of this type is 10.
460460
The significand is normalized to the number of digits of precision the type has (e.g. for decimal32 it is [1'000'000, 9'999'999]).
461461

462-
=== trunc_to
462+
=== rescale
463463

464464
[source, c++]
465465
----
466466
template <typename Decimal>
467-
constexpr Decimal trunc_to(Decimal val, int precision = 0);
467+
constexpr Decimal rescale(Decimal val, int precision = 0);
468468
----
469469

470470
The function returns the decimal type with number of fractional digits equal to the value of precision.
471-
`trunc_to` is similar to https://en.cppreference.com/w/cpp/numeric/math/trunc[trunc], and with the default precision argument of 0 it is identical.
471+
`rescale` is similar to https://en.cppreference.com/w/cpp/numeric/math/trunc[trunc], and with the default precision argument of 0 it is identical.

include/boost/decimal/cmath.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#include <boost/decimal/detail/cmath/assoc_laguerre.hpp>
7272
#include <boost/decimal/detail/cmath/legendre.hpp>
7373
#include <boost/decimal/detail/cmath/assoc_legendre.hpp>
74-
#include <boost/decimal/detail/cmath/trunc_to.hpp>
74+
#include <boost/decimal/detail/cmath/rescale.hpp>
7575
#include <boost/decimal/detail/cmath/beta.hpp>
7676
#include <boost/decimal/numbers.hpp>
7777

include/boost/decimal/detail/cmath/trunc_to.hpp renamed to include/boost/decimal/detail/cmath/rescale.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Copyright 2024 Matt Borland
1+
// Copyright 2025 Matt Borland
22
// Distributed under the Boost Software License, Version 1.0.
33
// https://www.boost.org/LICENSE_1_0.txt
44

5-
#ifndef BOOST_DECIMAL_DETAIL_CMATH_TRUNC_TO_HPP
6-
#define BOOST_DECIMAL_DETAIL_CMATH_TRUNC_TO_HPP
5+
#ifndef BOOST_DECIMAL_DETAIL_CMATH_RESCALE_HPP
6+
#define BOOST_DECIMAL_DETAIL_CMATH_RESCALE_HPP
77

88
#include <boost/decimal/fwd.hpp>
99
#include <boost/decimal/detail/type_traits.hpp>
@@ -24,7 +24,7 @@ namespace boost {
2424
namespace decimal {
2525

2626
BOOST_DECIMAL_EXPORT template <typename T>
27-
constexpr auto trunc_to(T val, int precision = 0) noexcept
27+
constexpr auto rescale(T val, int precision = 0) noexcept
2828
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
2929
{
3030
constexpr auto biggest_val {1 / std::numeric_limits<T>::epsilon()};
@@ -64,8 +64,15 @@ constexpr auto trunc_to(T val, int precision = 0) noexcept
6464
return {sig, exp, isneg};
6565
}
6666

67+
BOOST_DECIMAL_EXPORT template <typename T>
68+
[[deprecated("Renamed to rescale to match existing literature")]]
69+
constexpr auto trunc_to(T val, int precision = 0) noexcept
70+
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
71+
{
72+
return rescale(val, precision);
73+
}
6774

6875
} // namespace decimal
6976
} // namespace boost
7077

71-
#endif //BOOST_DECIMAL_DETAIL_CMATH_TRUNC_TO_HPP
78+
#endif //BOOST_DECIMAL_DETAIL_CMATH_RESCALE_HPP

test/cover/make_gcov_01_generic.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ gcov: objects
6363
@$(GNUECHO)
6464
@$(GNUECHO) +++ running lcov
6565
@$(LCOV) $(LCOV_BRANCH) -c --directory obj --output-file coverage_unfiltered.info
66-
@$(LCOV) $(LCOV_BRANCH) --remove coverage_unfiltered.info $(LCOV_REMOVES) --output-file coverage.info
66+
@$(LCOV) $(LCOV_BRANCH) --remove coverage_unfiltered.info $(LCOV_REMOVES) --ignore-errors unused --output-file coverage.info
6767
@$(GNUECHO)
6868
@$(GNUECHO) +++ running genhtml
6969
@$(GENHTML) coverage.info $(LCOV_BRANCH) --demangle-cpp --output-directory $(PATH_BIN)/report

test/cover/make_gcov_03_flags.gmk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ CXXFLAGS = -march=native \
3333
-Wall \
3434
-fno-inline-functions \
3535
-fprofile-arcs \
36-
-ftest-coverage
36+
-ftest-coverage \
37+
-std=$(STD)
3738

3839
C_DEFINES =
3940

0 commit comments

Comments
 (0)