-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample005_polylog_series.cpp
94 lines (71 loc) · 2.78 KB
/
example005_polylog_series.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
///////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2020 - 2022. //
// Distributed under the Boost Software License, //
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
///////////////////////////////////////////////////////////////////
#include <cmath>
#include <cstdint>
#include <deque>
#include <examples/example_decwide_t.h>
#include <math/wide_decimal/decwide_t.h>
namespace local_polylog
{
template<typename FloatingPointType>
auto polylog(std::int32_t s, const FloatingPointType& x) -> FloatingPointType;
template<typename FloatingPointType>
auto polylog(std::int32_t s, const FloatingPointType& x) -> FloatingPointType
{
using floating_point_type = FloatingPointType;
const floating_point_type tol = (x * std::numeric_limits<floating_point_type>::epsilon()) / 10U;
floating_point_type x_pow_k(x);
floating_point_type sum (x);
for(auto k = static_cast<std::uint_fast32_t>(UINT32_C(2));
k < static_cast<std::uint_fast32_t>(UINT32_C(100000));
++k)
{
x_pow_k *= x;
const floating_point_type k_pow_s = pow(floating_point_type(k), s);
const floating_point_type term = x_pow_k / k_pow_s;
if(term < tol)
{
break;
}
sum += term;
}
return sum;
}
} // namespace local_polylog
#if defined(WIDE_DECIMAL_NAMESPACE)
auto WIDE_DECIMAL_NAMESPACE::math::wide_decimal::example005_polylog_series() -> bool
#else
auto ::math::wide_decimal::example005_polylog_series() -> bool
#endif
{
#if defined(WIDE_DECIMAL_NAMESPACE)
using dec101_t = WIDE_DECIMAL_NAMESPACE::math::wide_decimal::decwide_t<static_cast<std::int32_t>(INT32_C(101))>;
#else
using dec101_t = ::math::wide_decimal::decwide_t<static_cast<std::int32_t>(INT32_C(101))>;
#endif
using std::fabs;
const dec101_t poly = local_polylog::polylog(7U, dec101_t(17U) / 71U);
// N[PolyLog[7, 17/71], 101]
const dec101_t control
{
"0.23989099751201076665599565769828454152030927256642802570721839696637617308754054721620440634024352282"
};
// Check the closeness of the result.
const dec101_t closeness = fabs(1 - (poly / control));
const auto result_is_ok = (closeness < (std::numeric_limits<dec101_t>::epsilon() * static_cast<std::uint32_t>(UINT8_C(10))));
return result_is_ok;
}
// Enable this if you would like to activate this main() as a standalone example.
#if defined(WIDE_DECIMAL_STANDALONE_EXAMPLE005_POLYLOG_SERIES)
#include <iomanip>
#include <iostream>
auto main() -> int
{
const auto result_is_ok = ::math::wide_decimal::example005_polylog_series();
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
}
#endif