Skip to content
Commit c325a11f authored by Alan Modra's avatar Alan Modra
Browse files

A little more precise %Lf for IBM long double

http://sourceware.org/ml/libc-alpha/2013-08/msg00106.html

IBM long double has variable precision and we often have values with
107 bits during the normal course of calculations.  It's possible to
have an IBM long double with 2k bits of precision, and while some might
argue we ought to print to the full precision, I'm not inclined to try
to implement that.

So this patch gives the mpn values returned from ldbl2mpn() an extra
11 bits of precision.  To do that it's necessary to inform the caller
of __mpn_extract_long_double() exactly how many bits are returned
rather than assuming a fixed LDBL_MANT_DIG bits.  I did that
indirectly by returning the number of zero bits in the last mp_limb,
which turns out to be convenient both in __mpn_extract_long_double(),
and it's caller.  Given the extra parameter it then becomes possible
to omit shifting in __mpn_extract_long_double(), since the caller does
that anyway.

In the following, note that 1 - IEEE854_LONG_DOUBLE_BIAS is equal to
LDBL_MIN_EXP - 1.  I prefer the former since we already use
IEEE854_LONG_DOUBLE_BIAS in the exponent calculation for normalised
values, and it reinforces the fact that denormals are treated as if
their unbiased exponent was 1.

	[BZ #5268]
	* include/gmp.h (__mpn_extract_double, __mpn_extract_long_double):
	Update prototypes.
	* stdio-common/printf_fp.c: Likewise.
	(__printf_fp): Use returned zero_bits.
	* stdlib/dbl2mpn.c (__mpn_extract_double): Update funtion arguments.
	* sysdeps/i386/ldbl2mpn.c (__mpn_extract_long_double): Don't perform
	shifts for denormals here.  Instead return leading zero bit count
	and adjust return value of function.
	* sysdeps/ieee754/dbl-64/dbl2mpn.c (__mpn_extract_long_double): Likewise.
	* sysdeps/ieee754/ldbl-128/ldbl2mpn.c (__mpn_extract_long_double):
	Likewise.
	* sysdeps/ieee754/ldbl-96/ldbl2mpn.c (__mpn_extract_long_double):
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c (__mpn_extract_long_double):
	Likewise.  Return an extra 11 bits of precision.
parent e24fc3c2
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment