Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>()` specialization:
```C++
const uint64_t W = 1234567;
const int Q = 23;
const double result = fast_float::integer_times_pow10<float>(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.

Expand Down
26 changes: 25 additions & 1 deletion tests/example_integer_times_pow10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@

#include <iostream>

int main() {
void default_overload() {
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 << 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<double>(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<float>(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();
}
Loading