This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Hexadecimal float sprintf, for perl #122219
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 12 Aug 2014 12:30:56 +0000 (08:30 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 14 Aug 2014 02:43:53 +0000 (22:43 -0400)
commit40bca5ae9c72f416f0e0e056ecf8e205a03e5be3
tree01368e1c00fe74a8ad59ba60ee768f55c4d7d046
parent981814452dab24c809cbbe2053d6dc7a6da77bed
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.
perl.h
pod/perldiag.pod
pod/perlfunc.pod
sv.c
t/op/sprintf.t
t/op/sprintf2.t