-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_compute_float80.cpp
More file actions
50 lines (41 loc) · 1.43 KB
/
test_compute_float80.cpp
File metadata and controls
50 lines (41 loc) · 1.43 KB
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
// Copyright 2023 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/charconv/detail/compute_float80.hpp>
#include <boost/charconv/detail/emulated128.hpp>
#include <boost/charconv/detail/bit_layouts.hpp>
#include <boost/core/lightweight_test.hpp>
#include <random>
#include <limits>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <iomanip>
// MSVC uses long double = double
// Darwin sometimes uses double-double instead of long double
#if BOOST_CHARCONV_LDBL_BITS > 64 && !defined(__APPLE__) && !defined(_WIN32) && !defined(_WIN64)
using boost::charconv::detail::compute_float80;
using boost::charconv::detail::uint128;
template <typename T>
inline void test_fast_path()
{
std::errc success;
BOOST_TEST_EQ(compute_float80<long double>(1, T(1), false, success), 10.0L);
BOOST_TEST_EQ(compute_float80<long double>(1, T(1), true, success), -10.0L);
BOOST_TEST_EQ(compute_float80<long double>(27, T(1) << 112, false, success), 5.1922968585348276285304963292200960000000000000000e60L);
BOOST_TEST_EQ(compute_float80<long double>(27, T(1) << 112, true, success), -5.1922968585348276285304963292200960000000000000000e60L);
}
int main()
{
test_fast_path<uint128>();
#ifdef BOOST_CHARCONV_HAS_INT128
test_fast_path<boost::uint128_type>();
#endif
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif