▲ | lifthrasiir 4 days ago | |||||||||||||||||||||||||
Except that C specifies that floating point numbers should be printed in a fixed precision (6 decimal digits) when no precision is given. Internally they do use some sort of float-to-decimal algorithms [1], but you can't get the shortest representation out of them. [1] Some (e.g. Windows CRT) do use the shortest representation as a basis, in which case you can actually extract it with large enough precision (where all subsequent digits will be zeros). But many libcs print the exact representation instead (e.g. 3.140000000000000124344978758017532527446746826171875 for `printf("%.51f", 3.14)`), so they are useless for our purpose. | ||||||||||||||||||||||||||
▲ | unnah 4 days ago | parent | next [-] | |||||||||||||||||||||||||
Ok, you got me there. Looks like they fixed that in C++17 with std::to_chars. https://en.cppreference.com/w/cpp/utility/to_chars.html | ||||||||||||||||||||||||||
▲ | Sharlin 4 days ago | parent | prev [-] | |||||||||||||||||||||||||
That's what the %g format specifier is for.
| ||||||||||||||||||||||||||
|