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_float32.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <limits>
8#include <cstdint>
9#include <cmath>
10
11using boost::charconv::detail::compute_float32;
12
13inline void simple_test()
14{
15 bool success;
16
17 // Trivial verifcation
18 BOOST_TEST_EQ(compute_float32(1, 1, false, success), 1e1F);
19 BOOST_TEST_EQ(compute_float32(0, 1, true, success), -1e0F);
20 BOOST_TEST_EQ(compute_float32(38, 1, false, success), 1e38F);
21
22 // out of range
23 BOOST_TEST_EQ(compute_float32(310, 5, false, success), HUGE_VALF);
24 BOOST_TEST_EQ(compute_float32(-325, 5, false, success), 0.0F);
25
26 // Composite
27 BOOST_TEST_EQ(compute_float32(10, 123456789, false, success), 123456789e10F);
28 BOOST_TEST_EQ(compute_float32(20, UINT64_C(444444444), false, success), 444444444e20F);
29}
30
31int main()
32{
33 simple_test();
34
35 return boost::report_errors();
36}
37

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