forked from ckormanyos/wide-integer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example006_gcd.cpp
86 lines (61 loc) · 2.85 KB
/
example006_gcd.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
///////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2018 - 2024. //
// 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 <examples/example_uintwide_t.h>
#include <math/wide_integer/uintwide_t.h>
#if defined(WIDE_INTEGER_NAMESPACE)
auto WIDE_INTEGER_NAMESPACE::math::wide_integer::example006_gcd() -> bool
#else
auto ::math::wide_integer::example006_gcd() -> bool
#endif
{
#if defined(WIDE_INTEGER_NAMESPACE)
using WIDE_INTEGER_NAMESPACE::math::wide_integer::uint256_t;
#else
using ::math::wide_integer::uint256_t;
#endif
auto result_is_ok = true;
{
constexpr auto a = uint256_t("0x1035452A5197CF882B5B5EB64C8CCFEE4D772F9F7B66A239649A43093464EFF5");
constexpr auto b = uint256_t("0xB4F6151D727361113083D9A0DEB91B0B62A250F65DA6543823703D0140C873AD");
constexpr auto c = gcd(a, b);
constexpr auto result_gcd_is_ok = (static_cast<std::uint32_t>(c) == static_cast<std::uint32_t>(UINT32_C(11759761)));
static_assert(result_gcd_is_ok, "Error: example006_gcd not OK!");
result_is_ok = (result_gcd_is_ok && result_is_ok);
}
{
constexpr auto a = uint256_t("0xD2690CD26CD57A3C443993851A70D3B62F841573668DF7B229508371A0AEDE7F");
constexpr auto b = uint256_t("0xFE719235CD0B1A314D4CA6940AEDC38BDF8E9484E68CE814EDAA17D87B0B4CC8");
constexpr auto c = gcd(a, b);
constexpr auto result_gcd_is_ok = (static_cast<std::uint32_t>(c) == static_cast<std::uint32_t>(UINT32_C(12170749)));
static_assert(result_gcd_is_ok, "Error: example006_gcd not OK!");
result_is_ok = (result_gcd_is_ok && result_is_ok);
}
{
constexpr auto a = uint256_t("0x7495AFF66DCB1085DC4CC294ECCBB1B455F65765DD4E9735564FDD80A05168A");
constexpr auto b = uint256_t("0x7A0543EF0705942D09962172ED5038814AE6EDF8EED2FC6C52CF317D253BC81F");
constexpr auto c = gcd(a, b);
constexpr auto result_gcd_is_ok = (static_cast<std::uint32_t>(c) == static_cast<std::uint32_t>(UINT32_C(13520497)));
static_assert(result_gcd_is_ok, "Error: example006_gcd not OK!");
result_is_ok = (result_gcd_is_ok && result_is_ok);
}
return result_is_ok;
}
// Enable this if you would like to activate this main() as a standalone example.
#if defined(WIDE_INTEGER_STANDALONE_EXAMPLE006_GCD)
#include <iomanip>
#include <iostream>
auto main() -> int
{
#if defined(WIDE_INTEGER_NAMESPACE)
const auto result_is_ok = WIDE_INTEGER_NAMESPACE::math::wide_integer::example006_gcd();
#else
const auto result_is_ok = ::math::wide_integer::example006_gcd();
#endif
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
return (result_is_ok ? 0 : -1);
}
#endif