to_chars general format doesn't produce shortest output in some cases
- Dominant language
- C++
- Stars
- 32
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
Using to_chars with general format seems to not produce the shortest output in some simple cases.
For example, comparing boost charconv, std charconv (gcc 14), and fmt:
```
#include
#include
#include
#include
int main()
{
double v = 0.1;
char buffer1[64] {};
auto r1 = boost::charconv::to_chars(buffer1, buffer1 + sizeof(buffer1), v, boost::charconv::chars_format::general);
std::cout << buffer1 << "\n";
char buffer2[64] {};
auto r2 = std::to_chars(buffer2, buffer2 + sizeof(buffer2), v, std::chars_format::general);
std::cout << buffer2 << "\n";
char buffer3[64] {};
fmt::format_to(buffer3, "{}", v);
std::cout << buffer3 << "\n";
}
```
Output:
```
1e-01
0.1
0.1
```
boost is selecting scientific instead of fixed here, even though fixed is shorter.
It seems like it may be an issue with values < 1, since 0.1234 and 0.12345678 also select the longer scientific format, but 1.1, 1.1234, and 1.12345678 select fixed as expected.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.