Skip to content

Commit

Permalink
Merge pull request #762 from cppalliance/rescale
Browse files Browse the repository at this point in the history
Refactor rescale
  • Loading branch information
mborland authored Jan 2, 2025
2 parents defb2dc + 384155e commit 44bf2bf
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 1,391 deletions.
6 changes: 3 additions & 3 deletions doc/decimal/cmath.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,13 @@ constexpr boost::decimal::detail::uint128 frexpd128(decimal128 num, int* expptr)
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.
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]).

=== trunc_to
=== rescale

[source, c++]
----
template <typename Decimal>
constexpr Decimal trunc_to(Decimal val, int precision = 0);
constexpr Decimal rescale(Decimal val, int precision = 0);
----

The function returns the decimal type with number of fractional digits equal to the value of precision.
`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.
`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.
2 changes: 1 addition & 1 deletion include/boost/decimal/cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#include <boost/decimal/detail/cmath/assoc_laguerre.hpp>
#include <boost/decimal/detail/cmath/legendre.hpp>
#include <boost/decimal/detail/cmath/assoc_legendre.hpp>
#include <boost/decimal/detail/cmath/trunc_to.hpp>
#include <boost/decimal/detail/cmath/rescale.hpp>
#include <boost/decimal/detail/cmath/beta.hpp>
#include <boost/decimal/numbers.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2024 Matt Borland
// Copyright 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_DECIMAL_DETAIL_CMATH_TRUNC_TO_HPP
#define BOOST_DECIMAL_DETAIL_CMATH_TRUNC_TO_HPP
#ifndef BOOST_DECIMAL_DETAIL_CMATH_RESCALE_HPP
#define BOOST_DECIMAL_DETAIL_CMATH_RESCALE_HPP

#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/type_traits.hpp>
Expand All @@ -24,7 +24,7 @@ namespace boost {
namespace decimal {

BOOST_DECIMAL_EXPORT template <typename T>
constexpr auto trunc_to(T val, int precision = 0) noexcept
constexpr auto rescale(T val, int precision = 0) noexcept
BOOST_DECIMAL_REQUIRES(detail::is_decimal_floating_point_v, T)
{
constexpr auto biggest_val {1 / std::numeric_limits<T>::epsilon()};
Expand Down Expand Up @@ -64,8 +64,15 @@ constexpr auto trunc_to(T val, int precision = 0) noexcept
return {sig, exp, isneg};
}

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

} // namespace decimal
} // namespace boost

#endif //BOOST_DECIMAL_DETAIL_CMATH_TRUNC_TO_HPP
#endif //BOOST_DECIMAL_DETAIL_CMATH_RESCALE_HPP
2 changes: 1 addition & 1 deletion test/cover/make_gcov_01_generic.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ gcov: objects
@$(GNUECHO)
@$(GNUECHO) +++ running lcov
@$(LCOV) $(LCOV_BRANCH) -c --directory obj --output-file coverage_unfiltered.info
@$(LCOV) $(LCOV_BRANCH) --remove coverage_unfiltered.info $(LCOV_REMOVES) --output-file coverage.info
@$(LCOV) $(LCOV_BRANCH) --remove coverage_unfiltered.info $(LCOV_REMOVES) --ignore-errors unused --output-file coverage.info
@$(GNUECHO)
@$(GNUECHO) +++ running genhtml
@$(GENHTML) coverage.info $(LCOV_BRANCH) --demangle-cpp --output-directory $(PATH_BIN)/report
Expand Down
3 changes: 2 additions & 1 deletion test/cover/make_gcov_03_flags.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ CXXFLAGS = -march=native \
-Wall \
-fno-inline-functions \
-fprofile-arcs \
-ftest-coverage
-ftest-coverage \
-std=$(STD)

C_DEFINES =

Expand Down
Loading

0 comments on commit 44bf2bf

Please sign in to comment.