|
| 1 | +// Copyright 2025 Matt Borland |
| 2 | +// Distributed under the Boost Software License, Version 1.0. |
| 3 | +// https://www.boost.org/LICENSE_1_0.txt |
| 4 | +// |
| 5 | +// See: https://github.com/boostorg/charconv/issues/266 |
| 6 | + |
| 7 | +#include <boost/charconv.hpp> |
| 8 | +#include <boost/core/lightweight_test.hpp> |
| 9 | + |
| 10 | +template <typename T> |
| 11 | +void test(T value, int precision, const char* correct_result) |
| 12 | +{ |
| 13 | + char buffer[64] {}; |
| 14 | + const auto r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), value, boost::charconv::chars_format::fixed, precision); |
| 15 | + BOOST_TEST_CSTR_EQ(buffer, correct_result); |
| 16 | + BOOST_TEST(r); |
| 17 | +} |
| 18 | + |
| 19 | +int main() |
| 20 | +{ |
| 21 | + test(123456789012345.6789012345678901, 5, "123456789012345.67188"); |
| 22 | + test(1234567890123456.789012345678901, 5, "1234567890123456.75000"); |
| 23 | + test(12345678901234567.89012345678901, 5, "12345678901234568.00000"); |
| 24 | + test(123456789012345678.9012345678901, 5, "123456789012345680.00000"); |
| 25 | + test(1234567890123456789.012345678901, 5, "1234567890123456768.00000"); |
| 26 | + |
| 27 | + test(123456789012345678901234567.8901, 5, "123456789012345678152597504.00000"); |
| 28 | + test(12345678901234567890123456.78901, 5, "12345678901234568244756480.00000"); |
| 29 | + test(1234567890123456789012345.678901, 5, "1234567890123456824475648.00000"); |
| 30 | + test(123456789012345678901234.5678901, 5, "123456789012345685803008.00000"); |
| 31 | + test(12345678901234567890123.45678901, 5, "12345678901234567741440.00000"); |
| 32 | + test(123456789012345678901.2345678901, 5, "123456789012345683968.00000"); |
| 33 | + |
| 34 | + return boost::report_errors(); |
| 35 | +} |
0 commit comments