Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logarithmic funcs #536

Merged
merged 5 commits into from
May 5, 2024
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
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/impl/cosh_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ constexpr typename cosh_table_imp<b>::d128_coeffs_t cosh_table_imp<b>::d128_coef
using cosh_table = cosh_detail::cosh_table_imp<true>;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto cosh_series_expansion(T z) noexcept;
constexpr auto cosh_series_expansion(T z2) noexcept;

template <>
constexpr auto cosh_series_expansion<decimal32>(decimal32 z2) noexcept
Expand Down
162 changes: 162 additions & 0 deletions include/boost/decimal/detail/cmath/impl/log1p_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright 2023 - 2024 Matt Borland
// Copyright 2023 - 2024 Christopher Kormanyos
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_DECIMAL_DETAIL_CMATH_IMPL_LOG1P_IMPL_HPP
#define BOOST_DECIMAL_DETAIL_CMATH_IMPL_LOG1P_IMPL_HPP

#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/detail/cmath/impl/taylor_series_result.hpp>

#ifndef BOOST_DECIMAL_BUILD_MODULE
#include <array>
#include <cstddef>
#include <cstdint>
#endif

namespace boost {
namespace decimal {
namespace detail {

namespace log1p_detail {

template <bool b>
struct log1p_table_imp
{
private:
using d32_coeffs_t = std::array<decimal32, 12>;
using d64_coeffs_t = std::array<decimal64, 20>;
using d128_coeffs_t = std::array<decimal128, 36>;

public:
static constexpr d32_coeffs_t d32_coeffs =
{{
// Series[Log[1 + x], {x, 0, 13}]
// (1), // * z
-boost::decimal::decimal32 { 5, -1 }, // * z^2
boost::decimal::decimal32 { UINT64_C(3333333333333333333), -19 }, // * z^3
-boost::decimal::decimal32 { 25, -2 }, // * z^4
boost::decimal::decimal32 { 2, -1 }, // * z^5
-boost::decimal::decimal32 { UINT64_C(1666666666666666667), -19 }, // * z^6
boost::decimal::decimal32 { UINT64_C(1428571428571428571), -19 }, // * z^7
-boost::decimal::decimal32 { 125, -3 }, // * z^8
boost::decimal::decimal32 { UINT64_C(1111111111111111111), -19 }, // * z^9
-boost::decimal::decimal32 { 1, -1 }, // * z^10
boost::decimal::decimal32 { UINT64_C(9090909090909090909), -19 - 1 }, // * z^11
-boost::decimal::decimal32 { UINT64_C(8333333333333333333), -19 - 1 }, // * z^12
boost::decimal::decimal32 { UINT64_C(7692307692307692308), -19 - 1 }, // * z^13
}};

static constexpr d64_coeffs_t d64_coeffs =
{{
// Series[Log[1 + x], {x, 0, 21}]
// (1), // * z
-boost::decimal::decimal64 { 5, -1 }, // * z^2
boost::decimal::decimal64 { UINT64_C(3333333333333333333), -19 }, // * z^3
-boost::decimal::decimal64 { 25, -2 }, // * z^4
boost::decimal::decimal64 { 2, -1 }, // * z^5
-boost::decimal::decimal64 { UINT64_C(1666666666666666667), -19 }, // * z^6
boost::decimal::decimal64 { UINT64_C(1428571428571428571), -19 }, // * z^7
-boost::decimal::decimal64 { 125, -3 }, // * z^8
boost::decimal::decimal64 { UINT64_C(1111111111111111111), -19 }, // * z^9
-boost::decimal::decimal64 { 1, -1 }, // * z^10
boost::decimal::decimal64 { UINT64_C(9090909090909090909), -19 - 1 }, // * z^11
-boost::decimal::decimal64 { UINT64_C(8333333333333333333), -19 - 1 }, // * z^12
boost::decimal::decimal64 { UINT64_C(7692307692307692308), -19 - 1 }, // * z^13
-boost::decimal::decimal64 { UINT64_C(7142857142857142857), -19 - 1 }, // * z^14
boost::decimal::decimal64 { UINT64_C(6666666666666666667), -19 - 1 }, // * z^15
-boost::decimal::decimal64 { UINT64_C(6250000000000000000), -19 - 1 }, // * z^16
boost::decimal::decimal64 { UINT64_C(5882352941176470588), -19 - 1 }, // * z^17
-boost::decimal::decimal64 { UINT64_C(5555555555555555556), -19 - 1 }, // * z^18
boost::decimal::decimal64 { UINT64_C(5263157894736842105), -19 - 1 }, // * z^19
-boost::decimal::decimal64 { 5, -2 }, // * z^20
boost::decimal::decimal64 { UINT64_C(4761904761904761905), -19 - 1 }, // * z^21
}};

static constexpr d128_coeffs_t d128_coeffs =
{{
// Series[Log[(1 + (z/2))/(1 - (z/2))], {z, 0, 43}]
// (1), // * z
-::boost::decimal::decimal128 { 5, -1 }, // * z^2
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(180700362080917), UINT64_C(7483252092553221458) }, -34 }, // * z^3
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(135525271560688), UINT64_C(1000753050987528192) }, -34 }, // * z^4
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(108420217248550), UINT64_C(8179300070273843200) }, -34 }, // * z^5
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(90350181040458), UINT64_C(12964998083131386532) }, -34 }, // * z^6
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(77443012320393), UINT64_C(3207108039665666332) }, -34 }, // * z^7
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(67762635780344), UINT64_C(500376525493764096) }, -34 }, // * z^8
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(60233454026972), UINT64_C(8643332055420924359) }, -34 }, // * z^9
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(54210108624275), UINT64_C(4089650035136921600) }, -34 }, // * z^10
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(492819169311592), UINT64_C(17054915875379776418) }, -35 }, // * z^11
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(451750905202293), UINT64_C(9484758194528277842) }, -35 }, // * z^12
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(417000835571347), UINT64_C(15850062977145160938) }, -35 }, // * z^13
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(387215061601965), UINT64_C(16035540198328331700) }, -35 }, // * z^14
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(361400724161834), UINT64_C(14966504185106442916) }, -35 }, // * z^15
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(338813178901720), UINT64_C(2501882627468820480) }, -35 }, // * z^16
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(318882991907501), UINT64_C(5610020838860575434) }, -35 }, // * z^17
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(301167270134862), UINT64_C(6323172129685518558) }, -35 }, // * z^18
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(285316361180395), UINT64_C(16670067533954968520) }, -35 }, // * z^19
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(271050543121376), UINT64_C(2001506101975056384) }, -35 }, // * z^20
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(258143374401310), UINT64_C(10690360132218887800) }, -35 }, // * z^21
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(246409584655796), UINT64_C(8527457937689888204) }, -35 }, // * z^22
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(235696124453370), UINT64_C(9760763598982462770) }, -35 }, // * z^23
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(225875452601146), UINT64_C(13965751134118914724) }, -35 }, // * z^24
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(216840434497100), UINT64_C(16358600140547686400) }, -35 }, // * z^25
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(208500417785673), UINT64_C(17148403525427356272) }, -35 }, // * z^26
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(200778180089908), UINT64_C(4215448086457012372) }, -35 }, // * z^27
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(193607530800982), UINT64_C(17241142136018941658) }, -35 }, // * z^28
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(186931409049224), UINT64_C(16646619993397598836) }, -35 }, // * z^29
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(180700362080917), UINT64_C(7483252092553221458) }, -35 }, // * z^30
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(174871318142823), UINT64_C(5456688082434451252) }, -35 }, // * z^31
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(169406589450860), UINT64_C(1250941313734410240) }, -35 }, // * z^32
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(164273056437197), UINT64_C(11833886649696442678) }, -35 }, // * z^33
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(159441495953750), UINT64_C(12028382456285063520) }, -35 }, // * z^34
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(154886024640786), UINT64_C(6414216079331332674) }, -35 }, // * z^35
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(150583635067431), UINT64_C(3161586064842759274) }, -35 }, // * z^36
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(146513807092635), UINT64_C(13545911456276754540) }, -35 }, // * z^37
}};
};

#if !(defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L) && (!defined(_MSC_VER) || _MSC_VER != 1900)

template <bool b>
constexpr typename log1p_table_imp<b>::d32_coeffs_t log1p_table_imp<b>::d32_coeffs;

template <bool b>
constexpr typename log1p_table_imp<b>::d64_coeffs_t log1p_table_imp<b>::d64_coeffs;

template <bool b>
constexpr typename log1p_table_imp<b>::d128_coeffs_t log1p_table_imp<b>::d128_coeffs;

#endif

} //namespace log1p_detail

using log1p_table = log1p_detail::log1p_table_imp<true>;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto log1p_series_expansion(T z2) noexcept;

template <>
constexpr auto log1p_series_expansion<decimal32>(decimal32 z2) noexcept
{
return taylor_series_result(z2, log1p_table::d32_coeffs);
}

template <>
constexpr auto log1p_series_expansion<decimal64>(decimal64 z2) noexcept
{
return taylor_series_result(z2, log1p_table::d64_coeffs);
}

template <>
constexpr auto log1p_series_expansion<decimal128>(decimal128 z2) noexcept
{
return taylor_series_result(z2, log1p_table::d128_coeffs);
}

} //namespace detail
} //namespace decimal
} //namespace boost

#endif //BOOST_DECIMAL_DETAIL_CMATH_IMPL_LOG1P_IMPL_HPP
134 changes: 134 additions & 0 deletions include/boost/decimal/detail/cmath/impl/log_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2023 - 2024 Matt Borland
// Copyright 2023 - 2024 Christopher Kormanyos
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_DECIMAL_DETAIL_CMATH_IMPL_LOG_IMPL_HPP
#define BOOST_DECIMAL_DETAIL_CMATH_IMPL_LOG_IMPL_HPP

#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/detail/cmath/impl/taylor_series_result.hpp>

#ifndef BOOST_DECIMAL_BUILD_MODULE
#include <array>
#include <cstddef>
#include <cstdint>
#endif

namespace boost {
namespace decimal {
namespace detail {

namespace log_detail {

template <bool b>
struct log_table_imp
{
private:
using d32_coeffs_t = std::array<decimal32, 8>;
using d64_coeffs_t = std::array<decimal64, 11>;
using d128_coeffs_t = std::array<decimal128, 21>;

public:
static constexpr d32_coeffs_t d32_coeffs =
{{
// Series[Log[(1 + (z/2))/(1 - (z/2))], {z, 0, 17}]
// (1), // * z
::boost::decimal::decimal32 { UINT64_C(8333333333333333333), - 19 - 1 }, // * z^3
::boost::decimal::decimal32 { UINT64_C(1250000000000000000), - 19 - 1 }, // * z^5
::boost::decimal::decimal32 { UINT64_C(2232142857142857143), - 19 - 2 }, // * z^7
::boost::decimal::decimal32 { UINT64_C(4340277777777777778), - 19 - 3 }, // * z^9
::boost::decimal::decimal32 { UINT64_C(8877840909090909091), - 19 - 4 }, // * z^11
::boost::decimal::decimal32 { UINT64_C(1878004807692307692), - 19 - 4 }, // * z^13
::boost::decimal::decimal32 { UINT64_C(4069010416666666667), - 19 - 5 }, // * z^15
::boost::decimal::decimal32 { UINT64_C(8975758272058823529), - 19 - 6 }, // * z^17
}};

static constexpr d64_coeffs_t d64_coeffs =
{{
// Series[Log[(1 + (z/2))/(1 - (z/2))], {z, 0, 23}]
// (1), // * z
::boost::decimal::decimal64 { UINT64_C(8333333333333333333), - 19 - 1 }, // * z^3
::boost::decimal::decimal64 { UINT64_C(1250000000000000000), - 19 - 1 }, // * z^5
::boost::decimal::decimal64 { UINT64_C(2232142857142857143), - 19 - 2 }, // * z^7
::boost::decimal::decimal64 { UINT64_C(4340277777777777778), - 19 - 3 }, // * z^9
::boost::decimal::decimal64 { UINT64_C(8877840909090909091), - 19 - 4 }, // * z^11
::boost::decimal::decimal64 { UINT64_C(1878004807692307692), - 19 - 4 }, // * z^13
::boost::decimal::decimal64 { UINT64_C(4069010416666666667), - 19 - 5 }, // * z^15
::boost::decimal::decimal64 { UINT64_C(8975758272058823529), - 19 - 6 }, // * z^17
::boost::decimal::decimal64 { UINT64_C(2007735402960526316), - 19 - 6 }, // * z^19
::boost::decimal::decimal64 { UINT64_C(4541306268601190476), - 19 - 7 }, // * z^21
::boost::decimal::decimal64 { UINT64_C(1036602517832880435), - 19 - 7 }, // * z^23
}};

static constexpr d128_coeffs_t d128_coeffs =
{{
// Series[Log[(1 + (z/2))/(1 - (z/2))], {z, 0, 43}]
// (1), // * z
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(451750905202293), UINT64_C(9484758194528277842) }, -35 }, // * z^3
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(67762635780344), UINT64_C(500376525493764096) }, -35 }, // * z^5
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(121004706750614), UINT64_C(6164027816584450626) }, -36 }, // * z^7
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(235286929792861), UINT64_C(3787056721709964394) }, -37 }, // * z^9
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(481268720030852), UINT64_C(8584740752302634068) }, -38 }, // * z^11
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(101806844621911), UINT64_C(1816002851448634124) }, -38 }, // * z^13
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(220581496680807), UINT64_C(7009130190423632548) }, -39 }, // * z^15
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(486576830913545), UINT64_C(12748560115094843630) }, -40 }, // * z^17
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(108839554283293), UINT64_C(2123490654414259032) }, -40 }, // * z^19
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(246184706116972), UINT64_C(9634423737622849438) }, -41 }, // * z^21
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(56194335091917), UINT64_C(11823550152479764302) }, -41 }, // * z^23
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(129246970711410), UINT64_C(10592095684364861440) }, -42 }, // * z^25
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(299182802572709), UINT64_C(12220910627630811506) }, -43 }, // * z^27
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(69637376460889), UINT64_C(5865971761607874066) }, -43 }, // * z^29
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(162861606239176), UINT64_C(11636108014793143194) }, -44 }, // * z^31
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(382478014652611), UINT64_C(14470401740943906374) }, -45 }, // * z^33
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(90155532025258), UINT64_C(9076666090147568782) }, -45 }, // * z^35
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(213205650059732), UINT64_C(16978042870933143358) }, -46 }, // * z^37
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(505680067449366), UINT64_C(9996854995997550184) }, -47 }, // * z^39
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(120253186771495), UINT64_C(12950434681540257980) }, -47 }, // * z^41
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(286650038234379), UINT64_C(5345076336561816786) }, -48 }, // * z^43
}};
};

#if !(defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L) && (!defined(_MSC_VER) || _MSC_VER != 1900)

template <bool b>
constexpr typename log_table_imp<b>::d32_coeffs_t log_table_imp<b>::d32_coeffs;

template <bool b>
constexpr typename log_table_imp<b>::d64_coeffs_t log_table_imp<b>::d64_coeffs;

template <bool b>
constexpr typename log_table_imp<b>::d128_coeffs_t log_table_imp<b>::d128_coeffs;

#endif

} //namespace log_detail

using log_table = log_detail::log_table_imp<true>;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto log_series_expansion(T z2) noexcept;

template <>
constexpr auto log_series_expansion<decimal32>(decimal32 z2) noexcept
{
return taylor_series_result(z2, log_table::d32_coeffs);
}

template <>
constexpr auto log_series_expansion<decimal64>(decimal64 z2) noexcept
{
return taylor_series_result(z2, log_table::d64_coeffs);
}

template <>
constexpr auto log_series_expansion<decimal128>(decimal128 z2) noexcept
{
return taylor_series_result(z2, log_table::d128_coeffs);
}

} //namespace detail
} //namespace decimal
} //namespace boost

#endif //BOOST_DECIMAL_DETAIL_CMATH_IMPL_LOG_IMPL_HPP
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/impl/sinh_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ constexpr typename sinh_table_imp<b>::d128_coeffs_t sinh_table_imp<b>::d128_coef
using sinh_table = sinh_detail::sinh_table_imp<true>;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto sinh_series_expansion(T z) noexcept;
constexpr auto sinh_series_expansion(T z2) noexcept;

template <>
constexpr auto sinh_series_expansion<decimal32>(decimal32 z2) noexcept
Expand Down
2 changes: 1 addition & 1 deletion include/boost/decimal/detail/cmath/impl/tanh_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ constexpr typename tanh_table_imp<b>::d128_coeffs_t tanh_table_imp<b>::d128_coef
using tanh_table = tanh_detail::tanh_table_imp<true>;

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto tanh_series_expansion(T z) noexcept;
constexpr auto tanh_series_expansion(T z2) noexcept;

template <>
constexpr auto tanh_series_expansion<decimal32>(decimal32 z2) noexcept
Expand Down
Loading
Loading