From 7abb574ffc55080713b528b6b0e271c541f07a53 Mon Sep 17 00:00:00 2001 From: Pavel Novikov Date: Mon, 29 Sep 2025 13:00:28 +0300 Subject: [PATCH] added doc to README and examples --- README.md | 17 +++++++++++++++++ tests/example_integer_times_pow10.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fdddbc..1c7e796 100644 --- a/README.md +++ b/README.md @@ -401,6 +401,23 @@ except `fast_float::integer_times_pow10()` does not report out-of-range errors, underflows to zero or overflows to infinity when the resulting value is out of range. +You can use template overloads to get the result converted to different +supported floating-point types: `float`, `double`, etc. +For example, to get result as `float` use +`fast_float::integer_times_pow10()` specialization: +```C++ +const uint64_t W = 1234567; +const int Q = 23; +const double result = fast_float::integer_times_pow10(W, Q); +std::cout.precision(7); +std::cout << "float: " << W << " * 10^" << Q << " = " << result << " (" + << (result == 1234567e23f ? "==" : "!=") << "expected)\n"; +``` +outputs +``` +float: 1234567 * 10^23 = 1.234567e+29 (==expected) +``` + Overloads of `fast_float::integer_times_pow10()` are provided for signed and unsigned integer types: `int64_t`, `uint64_t`, etc. diff --git a/tests/example_integer_times_pow10.cpp b/tests/example_integer_times_pow10.cpp index 3e86826..785daec 100644 --- a/tests/example_integer_times_pow10.cpp +++ b/tests/example_integer_times_pow10.cpp @@ -2,7 +2,7 @@ #include -int main() { +void default_overload() { const uint64_t W = 12345678901234567; const int Q = 23; const double result = fast_float::integer_times_pow10(W, Q); @@ -10,3 +10,27 @@ int main() { std::cout << W << " * 10^" << Q << " = " << result << " (" << (result == 12345678901234567e23 ? "==" : "!=") << "expected)\n"; } + +void double_specialization() { + const uint64_t W = 12345678901234567; + const int Q = 23; + const double result = fast_float::integer_times_pow10(W, Q); + std::cout.precision(17); + std::cout << "double: " << W << " * 10^" << Q << " = " << result << " (" + << (result == 12345678901234567e23 ? "==" : "!=") << "expected)\n"; +} + +void float_specialization() { + const uint64_t W = 1234567; + const int Q = 23; + const double result = fast_float::integer_times_pow10(W, Q); + std::cout.precision(7); + std::cout << "float: " << W << " * 10^" << Q << " = " << result << " (" + << (result == 1234567e23f ? "==" : "!=") << "expected)\n"; +} + +int main() { + default_overload(); + double_specialization(); + float_specialization(); +}