1// Copyright 2023 Matt Borland
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/charconv/detail/compute_float80.hpp>
6#include <boost/charconv/detail/emulated128.hpp>
7#include <boost/charconv/detail/bit_layouts.hpp>
8#include <boost/core/lightweight_test.hpp>
9#include <random>
10#include <limits>
11#include <cstdint>
12#include <cmath>
13#include <iostream>
14#include <iomanip>
15
16// MSVC uses long double = double
17// Darwin sometimes uses double-double instead of long double
18#if BOOST_CHARCONV_LDBL_BITS > 64 && !defined(__APPLE__) && !defined(_WIN32) && !defined(_WIN64)
19
20using boost::charconv::detail::compute_float80;
21using boost::charconv::detail::uint128;
22
23template <typename T>
24inline void test_fast_path()
25{
26 std::errc success;
27
28 BOOST_TEST_EQ(compute_float80<long double>(1, T(1), false, success), 10.0L);
29 BOOST_TEST_EQ(compute_float80<long double>(1, T(1), true, success), -10.0L);
30 BOOST_TEST_EQ(compute_float80<long double>(27, T(1) << 112, false, success), 5.1922968585348276285304963292200960000000000000000e60L);
31 BOOST_TEST_EQ(compute_float80<long double>(27, T(1) << 112, true, success), -5.1922968585348276285304963292200960000000000000000e60L);
32}
33
34int main()
35{
36 test_fast_path<uint128>();
37
38 #ifdef BOOST_CHARCONV_HAS_INT128
39 test_fast_path<boost::uint128_type>();
40 #endif
41
42 return boost::report_errors();
43}
44
45#else
46int main()
47{
48 return 0;
49}
50#endif
51

source code of boost/libs/charconv/test/test_compute_float80.cpp