-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexample000_multiply_nines.cpp
75 lines (59 loc) · 2.46 KB
/
example000_multiply_nines.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
///////////////////////////////////////////////////////////////////
// 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>
#include <util/memory/util_n_slot_array_allocator.h>
#if defined(WIDE_DECIMAL_NAMESPACE)
auto WIDE_DECIMAL_NAMESPACE::math::wide_decimal::example000_multiply_nines() -> bool
#else
auto ::math::wide_decimal::example000_multiply_nines() -> bool
#endif
{
using local_limb_type = std::uint8_t;
constexpr std::int32_t wide_decimal_digits10 = INT32_C(50);
#if defined(WIDE_DECIMAL_NAMESPACE)
using wide_decimal_type =
WIDE_DECIMAL_NAMESPACE::math::wide_decimal::decwide_t<wide_decimal_digits10,
local_limb_type,
void,
float,
std::int16_t>;
#else
using wide_decimal_type =
::math::wide_decimal::decwide_t<wide_decimal_digits10,
local_limb_type,
void,
float,
std::int16_t>;
#endif
const wide_decimal_type a
{
( std::string("9.")
+ std::string(wide_decimal_digits10 - 1, '9')).c_str()
};
const wide_decimal_type control
{
( std::string("99.")
+ std::string(wide_decimal_digits10 - 3, '9')
+ std::string("8")).c_str()
};
const wide_decimal_type result = (a * a);
const wide_decimal_type closeness = fabs(1 - fabs(result / control));
const auto result_is_ok = (closeness < (std::numeric_limits<wide_decimal_type>::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_EXAMPLE000_MULTIPLY_NINES)
#include <iomanip>
#include <iostream>
auto main() -> int
{
const auto result_is_ok = ::math::wide_decimal::example000_multiply_nines();
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
}
#endif