-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample001a_roots_seventh.cpp
53 lines (40 loc) · 1.8 KB
/
example001a_roots_seventh.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
///////////////////////////////////////////////////////////////////
// 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 <cstdint>
#include <examples/example_decwide_t.h>
#include <math/wide_decimal/decwide_t.h>
#if defined(WIDE_DECIMAL_NAMESPACE)
auto WIDE_DECIMAL_NAMESPACE::math::wide_decimal::example001a_roots_seventh() -> bool
#else
auto ::math::wide_decimal::example001a_roots_seventh() -> 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)), std::uint32_t, void>;
#else
using dec101_t = ::math::wide_decimal::decwide_t<static_cast<std::int32_t>(INT32_C(101)), std::uint32_t, void>;
#endif
const dec101_t r7 = rootn(dec101_t(123456U) / 100, 7);
// N[(123456/100)^(1/7), 101]
const dec101_t control
{
"2.7646782775741109196428393776807250048855576457486681034865195752391286191642449378095974978251349039"
};
const dec101_t closeness = fabs(1 - fabs(r7 / 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_EXAMPLE001A_ROOTS_SEVENTH)
#include <iomanip>
#include <iostream>
auto main() -> int
{
const auto result_is_ok = ::math::wide_decimal::example001a_roots_seventh();
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
}
#endif