From: Ulrich Drepper Date: Wed, 28 Jul 1999 22:40:32 +0000 (+0000) Subject: Use IEEE 854 formula to compute the number of digits to print. X-Git-Tag: cvs/glibc_2-1-2~201 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0eb7585e82e55b744f5d0e1d91fba216e86ce356;p=thirdparty%2Fglibc.git Use IEEE 854 formula to compute the number of digits to print. --- diff --git a/misc/efgcvt.c b/misc/efgcvt.c index 9348914ff2b..dc711c63dcd 100644 --- a/misc/efgcvt.c +++ b/misc/efgcvt.c @@ -17,6 +17,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include #include #include @@ -29,8 +30,13 @@ # define FLOAT_FMT_FLAG /* Actually we have to write (DBL_DIG + log10 (DBL_MAX_10_EXP)) but we don't have log10 available in the preprocessor. */ -# define MAXDIG (DBL_DIG + 3) -# define NDIGIT_MAX DBL_DIG +# define MAXDIG (NDIGIT_MAX + 3) +# if DBL_MANT_DIG == 53 +# define NDIGIT_MAX 17 +# else +/* See IEEE 854 5.6, table 2 for this formula. */ +# define NDIGIT_MAX (lrint (ceil (M_LN2 / M_LN10 * DBL_MANT_DIG + 1.0))) +# endif #endif #define APPEND(a, b) APPEND2 (a, b) diff --git a/misc/efgcvt_r.c b/misc/efgcvt_r.c index 944fe4cc984..d73fd22f70f 100644 --- a/misc/efgcvt_r.c +++ b/misc/efgcvt_r.c @@ -30,7 +30,12 @@ # define FUNC_PREFIX # define FLOAT_FMT_FLAG # define FLOAT_NAME_EXT -# define NDIGIT_MAX DBL_DIG +# if DBL_MANT_DIG == 53 +# define NDIGIT_MAX 17 +# else +/* See IEEE 854 5.6, table 2 for this formula. */ +# define NDIGIT_MAX (lrint (ceil (M_LN2 / M_LN10 * DBL_MANT_DIG + 1.0))) +# endif #endif #define APPEND(a, b) APPEND2 (a, b) diff --git a/misc/qefgcvt.c b/misc/qefgcvt.c index af65fc1688e..faf788aa5d4 100644 --- a/misc/qefgcvt.c +++ b/misc/qefgcvt.c @@ -17,13 +17,20 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + #define FLOAT_TYPE long double #define FUNC_PREFIX q #define FLOAT_FMT_FLAG "L" /* Actually we have to write (LDBL_DIG + log10 (LDBL_MAX_10_EXP)) but we don't have log10 available in the preprocessor. Since we cannot assume anything on the used `long double' format be generous. */ -#define MAXDIG (LDBL_DIG + 12) -#define NDIGIT_MAX LDBL_DIG +#define MAXDIG (NDIGIT_MAX + 12) +#if LDBL_MANT_DIG == 64 +# define NDIGIT_MAX 21 +#else +/* See IEEE 854 5.6, table 2 for this formula. */ +# define NDIGIT_MAX (lrint (ceil (M_LN2 / M_LN10 * LDBL_MANT_DIG + 1.0))) +#endif #include "efgcvt.c" diff --git a/misc/qefgcvt_r.c b/misc/qefgcvt_r.c index 012ab54acc4..5ff8110e3bb 100644 --- a/misc/qefgcvt_r.c +++ b/misc/qefgcvt_r.c @@ -18,10 +18,17 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + #define FLOAT_TYPE long double #define FUNC_PREFIX q #define FLOAT_FMT_FLAG "L" #define FLOAT_NAME_EXT l -# define NDIGIT_MAX LDBL_DIG +#if LDBL_MANT_DIG == 64 +# define NDIGIT_MAX 21 +#else +/* See IEEE 854 5.6, table 2 for this formula. */ +# define NDIGIT_MAX (lrint (ceil (M_LN2 / M_LN10 * LDBL_MANT_DIG + 1.0))) +#endif #include "efgcvt_r.c"