This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Hexadecimal float sprintf, for perl #122219
Do not use the system sprintf since %a/%A is C99 (which we do not
require), and even if we did, there is room for interpretation
(for example whether to print trailing zeros or not) which means
that existing implementations will inevitably differ.
For the most common case, 64-bit doubles of IEEE 754, use first
frexp to extract the exponent, and then ldexp to scale the result
to a 64-bit unsigned integer.
For long doubles (80-bit or 128-bit) we look directly at the mantissa
(also known as fraction, or significand) bytes, and their 4-bit nybbles,
and extract them in correct order.
Since we bypass system printf, we need to do our own aligning, filling,
rounding, and other printf logic.