Skip to content

Commit 7abb574

Browse files
committed
added doc to README and examples
1 parent 01e5057 commit 7abb574

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,23 @@ except `fast_float::integer_times_pow10()` does not report out-of-range errors,
401401
underflows to zero or overflows to infinity when the resulting value is
402402
out of range.
403403

404+
You can use template overloads to get the result converted to different
405+
supported floating-point types: `float`, `double`, etc.
406+
For example, to get result as `float` use
407+
`fast_float::integer_times_pow10<float>()` specialization:
408+
```C++
409+
const uint64_t W = 1234567;
410+
const int Q = 23;
411+
const double result = fast_float::integer_times_pow10<float>(W, Q);
412+
std::cout.precision(7);
413+
std::cout << "float: " << W << " * 10^" << Q << " = " << result << " ("
414+
<< (result == 1234567e23f ? "==" : "!=") << "expected)\n";
415+
```
416+
outputs
417+
```
418+
float: 1234567 * 10^23 = 1.234567e+29 (==expected)
419+
```
420+
404421
Overloads of `fast_float::integer_times_pow10()` are provided for
405422
signed and unsigned integer types: `int64_t`, `uint64_t`, etc.
406423

tests/example_integer_times_pow10.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,35 @@
22

33
#include <iostream>
44

5-
int main() {
5+
void default_overload() {
66
const uint64_t W = 12345678901234567;
77
const int Q = 23;
88
const double result = fast_float::integer_times_pow10(W, Q);
99
std::cout.precision(17);
1010
std::cout << W << " * 10^" << Q << " = " << result << " ("
1111
<< (result == 12345678901234567e23 ? "==" : "!=") << "expected)\n";
1212
}
13+
14+
void double_specialization() {
15+
const uint64_t W = 12345678901234567;
16+
const int Q = 23;
17+
const double result = fast_float::integer_times_pow10<double>(W, Q);
18+
std::cout.precision(17);
19+
std::cout << "double: " << W << " * 10^" << Q << " = " << result << " ("
20+
<< (result == 12345678901234567e23 ? "==" : "!=") << "expected)\n";
21+
}
22+
23+
void float_specialization() {
24+
const uint64_t W = 1234567;
25+
const int Q = 23;
26+
const double result = fast_float::integer_times_pow10<float>(W, Q);
27+
std::cout.precision(7);
28+
std::cout << "float: " << W << " * 10^" << Q << " = " << result << " ("
29+
<< (result == 1234567e23f ? "==" : "!=") << "expected)\n";
30+
}
31+
32+
int main() {
33+
default_overload();
34+
double_specialization();
35+
float_specialization();
36+
}

0 commit comments

Comments
 (0)