-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample013a_embeddable_agm.cpp
154 lines (129 loc) · 5.87 KB
/
example013a_embeddable_agm.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
///////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 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) //
///////////////////////////////////////////////////////////////////
#if (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 12))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
#include <algorithm>
#include <array>
#include <cstdint>
#if (defined(__GNUC__) && defined(__AVR__))
#include <avr/pgmspace.h>
#define MY_PROGMEM PROGMEM
#else
#define MY_PROGMEM
#endif
#define WIDE_DECIMAL_DISABLE_IOSTREAM
#define WIDE_DECIMAL_DISABLE_DYNAMIC_MEMORY_ALLOCATION
#define WIDE_DECIMAL_DISABLE_CONSTRUCT_FROM_STRING
#define WIDE_DECIMAL_DISABLE_CACHED_CONSTANTS
#define WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION
#include <examples/example_decwide_t.h>
#include <math/wide_decimal/decwide_t.h>
#include <util/memory/util_n_slot_array_allocator.h>
#if(__cplusplus >= 201703L)
namespace mcal::memory::progmem {
#else
namespace mcal { namespace memory { namespace progmem { // NOLINT(modernize-concat-nested-namespaces)
#endif
using std::array;
#if(__cplusplus >= 201703L)
} // namespace mcal::memory::progmem
#else
} // namespace progmem
} // namespace memory
} // namespace mcal
#endif
#if defined(WIDE_DECIMAL_NAMESPACE)
auto WIDE_DECIMAL_NAMESPACE::math::wide_decimal::example013a_embeddable_agm() -> bool
#else
auto ::math::wide_decimal::example013a_embeddable_agm() -> bool
#endif
{
// N[Pi, 106] and truncate the final digit.
using local_limb_type = std::uint16_t;
constexpr std::int32_t wide_decimal_digits10 = INT32_C(53);
#if defined(WIDE_DECIMAL_NAMESPACE)
constexpr std::int32_t local_elem_number =
WIDE_DECIMAL_NAMESPACE::math::wide_decimal::detail::decwide_t_helper<wide_decimal_digits10, local_limb_type>::elem_number;
#else
constexpr std::int32_t local_elem_number =
::math::wide_decimal::detail::decwide_t_helper<wide_decimal_digits10, local_limb_type>::elem_number;
#endif
using local_allocator_type = util::n_slot_array_allocator<void, local_elem_number, 18U>; // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
#if defined(WIDE_DECIMAL_NAMESPACE)
using dec53_t = WIDE_DECIMAL_NAMESPACE::math::wide_decimal::decwide_t<wide_decimal_digits10,
local_limb_type,
local_allocator_type,
float,
std::int16_t,
float>;
#else
using dec53_t = ::math::wide_decimal::decwide_t<wide_decimal_digits10,
local_limb_type,
local_allocator_type,
float,
std::int16_t,
float>;
#endif
static const mcal::memory::progmem::array<typename dec53_t::limb_type, 14U> app_benchmark_pi_agm_control MY_PROGMEM =
{{
static_cast<typename dec53_t::limb_type>(UINT16_C( 3)),
static_cast<typename dec53_t::limb_type>(UINT16_C(1415)),
static_cast<typename dec53_t::limb_type>(UINT16_C(9265)),
static_cast<typename dec53_t::limb_type>(UINT16_C(3589)),
static_cast<typename dec53_t::limb_type>(UINT16_C(7932)),
static_cast<typename dec53_t::limb_type>(UINT16_C(3846)),
static_cast<typename dec53_t::limb_type>(UINT16_C(2643)),
static_cast<typename dec53_t::limb_type>(UINT16_C(3832)),
static_cast<typename dec53_t::limb_type>(UINT16_C(7950)),
static_cast<typename dec53_t::limb_type>(UINT16_C(2884)),
static_cast<typename dec53_t::limb_type>(UINT16_C(1971)),
static_cast<typename dec53_t::limb_type>(UINT16_C(6939)),
static_cast<typename dec53_t::limb_type>(UINT16_C(9375)),
static_cast<typename dec53_t::limb_type>(UINT16_C(1058))
}};
#if defined(WIDE_DECIMAL_NAMESPACE)
const dec53_t my_pi =
WIDE_DECIMAL_NAMESPACE::math::wide_decimal::pi<wide_decimal_digits10,
local_limb_type,
local_allocator_type,
float,
std::int16_t,
float>();
#else
const dec53_t my_pi =
::math::wide_decimal::pi<wide_decimal_digits10,
local_limb_type,
local_allocator_type,
float,
std::int16_t,
float>();
#endif
const auto result_is_ok = std::equal(app_benchmark_pi_agm_control.cbegin(),
app_benchmark_pi_agm_control.cend(),
my_pi.crepresentation().cbegin());
return result_is_ok;
}
// Enable this if you would like to activate this main() as a standalone example.
#if defined(WIDE_DECIMAL_STANDALONE_EXAMPLE013A_EMBEDDABLE_AGM)
#if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM)
#include <iomanip>
#include <iostream>
#endif
auto main() -> int
{
const auto result_is_ok = ::math::wide_decimal::example013a_embeddable_agm();
#if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM)
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
#endif
return (result_is_ok ? 0 : -1);
}
#endif // WIDE_DECIMAL_STANDALONE_EXAMPLE013A_EMBEDDABLE_AGM
#if (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 12))
#pragma GCC diagnostic pop
#endif