From 9501d30c09a7746759fbf1dfc01dd5b7dd1a2b13 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 13 Mar 2023 10:23:01 -0700 Subject: [PATCH] Add functions for powers and factors --- .../boost/charconv/detail/power_factor.hpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/boost/charconv/detail/power_factor.hpp diff --git a/include/boost/charconv/detail/power_factor.hpp b/include/boost/charconv/detail/power_factor.hpp new file mode 100644 index 0000000..c221ac2 --- /dev/null +++ b/include/boost/charconv/detail/power_factor.hpp @@ -0,0 +1,43 @@ +// Copyright 2020-2023 Junekey Jeon +// Copyright 2023 Matt Borland +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_CHARCONV_DETAIL_POWER_FACTOR_HPP +#define BOOST_CHARCONV_DETAIL_POWER_FACTOR_HPP + +#include +#include + +namespace boost { namespace charconv { namespace detail { + +template +BOOST_CHARCONV_CXX14_CONSTEXPR Integer compute_power(Integer a) noexcept +{ + Integer p = 1; + for (Integer i = 0; i < k; ++i) + { + p *= a; + } + + return p; +} + +template +BOOST_CHARCONV_CXX14_CONSTEXPR int count_factors(Unsigned_Integer n) noexcept +{ + static_assert(a > 1); + + int c = 0; + while (n % a == 0) + { + n /= a; + ++c; + } + + return c; +} + +}}} // Namespaces + +#endif // BOOST_CHARCONV_DETAIL_POWER_FACTOR_HPP