mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 08:46:49 +08:00
added doc to README and examples
This commit is contained in:
parent
01e505797b
commit
7abb574ffc
17
README.md
17
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
|
underflows to zero or overflows to infinity when the resulting value is
|
||||||
out of range.
|
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
|
Overloads of `fast_float::integer_times_pow10()` are provided for
|
||||||
signed and unsigned integer types: `int64_t`, `uint64_t`, etc.
|
signed and unsigned integer types: `int64_t`, `uint64_t`, etc.
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
void default_overload() {
|
||||||
const uint64_t W = 12345678901234567;
|
const uint64_t W = 12345678901234567;
|
||||||
const int Q = 23;
|
const int Q = 23;
|
||||||
const double result = fast_float::integer_times_pow10(W, Q);
|
const double result = fast_float::integer_times_pow10(W, Q);
|
||||||
@ -10,3 +10,27 @@ int main() {
|
|||||||
std::cout << W << " * 10^" << Q << " = " << result << " ("
|
std::cout << W << " * 10^" << Q << " = " << result << " ("
|
||||||
<< (result == 12345678901234567e23 ? "==" : "!=") << "expected)\n";
|
<< (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…
x
Reference in New Issue
Block a user