Re: [PATCH 2/3] Fix gcvt to always show 'ndigits' of precision

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Dec 17 22:00, Keith Packard wrote:
> Leading zeros after the decimal point should not count
> towards the 'ndigits' limit.
> 
> This makes gcvt match glibc and the posix gcvt man page.
> 
> Signed-off-by: Keith Packard <[email protected]>
> ---
>  newlib/libc/stdlib/ecvtbuf.c | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/newlib/libc/stdlib/ecvtbuf.c b/newlib/libc/stdlib/ecvtbuf.c
> index 0a5d41a0f..8936363ce 100644
> --- a/newlib/libc/stdlib/ecvtbuf.c
> +++ b/newlib/libc/stdlib/ecvtbuf.c
> @@ -349,15 +349,10 @@ _gcvt (struct _reent *ptr,
>        char *end;
>        char *p;
>  
> -      if (invalue < 1.0)
> -	{
> -	  /* what we want is ndigits after the point */
> -	  p = _dtoa_r (ptr, invalue, 3, ndigit, &decpt, &sign, &end);
> -	}
> -      else
> -	{
> -	  p = _dtoa_r (ptr, invalue, 2, ndigit, &decpt, &sign, &end);
> -	}
> +      /* We always want ndigits of precision, even if that means printing
> +       * a bunch of leading zeros for numbers < 1.0
> +       */
> +      p = _dtoa_r (invalue, 2, ndigit, &decpt, &sign, &end);
                   ^^^^^
                same here.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl356UQACgkQ9TYGna5E
T6BKbRAAgrkZqWNi6LUVLxCuK3yQZL/laixCy956N0nbZG2wSl65Y+oTBTAEfA+S
8m6iylJeHdmqTdUgehYXK0WqUldjSsruY2FRblMYyFhcubF5fsXKtaDAU3LxPagT
sF7YDctgD71yixUczfS908ASa7NzTb1Kxq/xqRiQBRmqCcMoTOmMAr+RMumIQael
eJkEQLW2AfvjIAoq4EbK7jucwd5NUelrEUgLwrCBpiLaDrcdVljVQZp3jbHzCOZX
GGX5W7+mW4l0B2cUIxU7h1Or6trODcvpmGt+H1HrfH4lZjsaDhQlAyvRx2diz5Hj
K0E9v+Uf6YtotClS+dRqRELY0OVLRSYFD+tG4rYyublUcvdfzoHbTRuj1h6dUYmQ
4Xt8rvxukQ8veKZXE2r9Iubi2FAljd1bQgsY+S/DanoqL+3iQgGow9aAiP44lSpS
SZga2GLfuJhOyR+c5wKgFmqeW2T/Y2u7I5sUOSSQ6ZLCwZXdy7M36p97tb44C4xj
lGMqvOm/kqyYp3QtPcpTlhBWFSDLT/R3ZW2bGJwbVhgl7tdqANK4d+bnK1lG8Pnk
3dgV/Vqq089IcL6J+IaJU54nKpamMrdDVUtGfdYXB1bCCLGbdSTq9zy497s8V1lI
S6ErmAYkeusNk+oW8Qq7Np4oheINHwSAMyQU+yiyO5IqaJpNWHM=
=Eh4v
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.