-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample001_roots_sqrt.cpp
63 lines (47 loc) · 2.09 KB
/
example001_roots_sqrt.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
///////////////////////////////////////////////////////////////////
// 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 <math/softfloat/soft_double.h>
#include <math/softfloat/soft_double_examples.h>
static_assert(sizeof(double) == 8U, // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
"Error: This example requires 8 byte built-in double for verification");
auto math::softfloat::example001_roots_sqrt() -> bool
{
// Use a cached value for pi.
constexpr float64_t my_pi = float64_t::my_value_pi();
// Compute soft_double sqrt(pi).
#if (defined(_MSC_VER) && (_MSC_VER < 1920))
#pragma warning(push)
#pragma warning(disable : 4307)
#endif
constexpr float64_t s = sqrt(my_pi);
#if (defined(_MSC_VER) && (_MSC_VER < 1920))
#pragma warning(pop)
#endif
using std::sqrt;
// Compare with native double sqrt(pi).
const auto result_root_is_ok =
(s.crepresentation() == float64_t(sqrt(3.1415926535897932384626433832795028841972)).crepresentation());
constexpr auto result_root_as_constexpr_is_ok =
(s.crepresentation() == static_cast<typename float64_t::representation_type>(UINT64_C(0x3FFC5BF891B4EF6A)));
#if (defined(SOFT_DOUBLE_CONSTEXPR_IS_COMPILE_TIME_CONST) && (SOFT_DOUBLE_CONSTEXPR_IS_COMPILE_TIME_CONST != 0))
static_assert(result_root_as_constexpr_is_ok, "Error: example001_roots_sqrt not OK!");
#endif
const auto result_is_ok = (result_root_is_ok && result_root_as_constexpr_is_ok);
return result_is_ok;
}
// Enable this if you would like to activate this main() as a standalone example.
#if 0
#include <iomanip>
#include <iostream>
int main()
{
const bool result_is_ok = math::softfloat::example001_roots_sqrt();
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
}
#endif