Date: Sun, 11 Jul 2004 11:38:17 -0700 (PDT) From: "Bruce R. Montague" <brucem@mail.cruzio.com> To: freebsd-hackers@freebsd.org Cc: marck@rinet.ru Subject: Re: gcc strangeness Message-ID: <200407111838.i6BIcHku000792@mail.cruzio.com>
next in thread | raw e-mail | index | archive | help
Hi, re: >one of my friends has raisen very strange issue regarding gcc rounding: > printf("%f %.3f %d\n", a*100, a*100, (int)(a*100)); > > 9.999999 10.000 9 Hasty unresearched guess: If you print with a large fp fmt (say 22.18) you will get a better idea of the value: 9.999999403953552246 10.000 9 The "%.3f" says to round upward to inf after 3 decimal places, so "9.9999" is rounded to "10.000". The "%f" defaults to round up after 6 decimal places, so "9.9999994" is rounded to ""9.999999". Everything is working. There are a lot of subtleties in floating-point printf(). Printing binary values out and reading them back accurately can be a non-trivial exercise. - bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200407111838.i6BIcHku000792>