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_float64.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <random>
8#include <limits>
9#include <cstdint>
10#include <cmath>
11
12using boost::charconv::detail::compute_float64;
13
14inline void simple_test()
15{
16 bool success;
17
18 // Trivial verifcation
19 BOOST_TEST_EQ(compute_float64(1, 1, false, success), 1e1);
20 BOOST_TEST_EQ(compute_float64(0, 1, true, success), -1e0);
21 BOOST_TEST_EQ(compute_float64(308, 1, false, success), 1e308);
22
23 // out of range
24 BOOST_TEST_EQ(compute_float64(310, 5, false, success), HUGE_VAL);
25 BOOST_TEST_EQ(compute_float64(-325, 5, false, success), 0);
26
27 // Composite
28 BOOST_TEST_EQ(compute_float64(10, 123456789, false, success), 123456789e10);
29 BOOST_TEST_EQ(compute_float64(100, UINT64_C(4444444444444444444), false, success), 4444444444444444444e100);
30}
31
32int main(void)
33{
34 simple_test();
35
36 return boost::report_errors();
37}
38

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