What is required printf precision for a __float128 to not lose information?
If you're on x86, then the GCC __float128 type is a software implementation of the IEEE 754-2008 binary128 format. The IEEE 754 standard requires that a binary -> char -> binary roundtrip recovers the original value if the character representation contains 36 significant (decimal) digits. Thus the format string %.36Qg
ought to do it.
It is not required that a NaN roundtrip recover the original bitwise value.
As for your requirement #3, libquadmath does not contain code for this kind of "shortest representation" formatting, e.g. in the spirit of the Steele & White paper or the code by David Gay.