This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: printf("%.0f", 0.5) and round-to-even


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 9/30/2008 12:59 PM:
>>> It looks like the printf family could use a QoI improvement when dealing 
> with 
>>> IEEE round-to-even rules.
> 
> OK to apply this patch?
> 
> 2008-09-30  Eric Blake  <ebb9@byu.net>
> 
> 	* libc/stdlib/ldtoa.c (etoasc): Fix rounding to even when fraction
> 	is 0.5 or 0.75.
> 
> Index: libc/stdlib/ldtoa.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/stdlib/ldtoa.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 ldtoa.c
> --- libc/stdlib/ldtoa.c 6 Jun 2007 19:24:28 -0000       1.12
> +++ libc/stdlib/ldtoa.c 30 Sep 2008 18:34:48 -0000
> @@ -3153,7 +3153,7 @@ if( digit > 4 )
>                 emovo( y, t, ldp );
>                 if( ecmp(t,ezero) != 0 )
>                         goto roun;      /* round to nearest */
> -               if( (*(s-1) & 1) == 0 )
> +               if( ndigs < 0 || (*(s-1-(*(s-1)=='.')) & 1) == 0)
>                         goto doexp;     /* round to even */
>                 }
>  /* Round up and propagate carry-outs */
> 

Ping.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjqZIgACgkQ84KuGfSFAYD8IACdG2BRDgf9i9hQl+YrkRDmBP6F
GQcAn144UZO72Gh/HtMlMzg5QOwfmWoi
=8HrR
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]