Dear Ilko Iliev, In message <[EMAIL PROTECTED]> you wrote: > This patch prevents the displaying of results like this: > hz = 1999170000 > buf = "200.-83"
I think you got one '0' too many in your example - the example would just print "1999.170" which is correct. > --- a/lib_generic/strmhz.c > +++ b/lib_generic/strmhz.c > @@ -28,10 +28,15 @@ char *strmhz (char *buf, long hz) > long m; > > n = DIV_ROUND(hz, 1000000L); > - l = sprintf (buf, "%ld", n); > > hz -= n * 1000000L; > m = DIV_ROUND(hz, 1000L); > + if ( m < 0 ) { > + n--; > + m += 1000L; > + } > + > + l = sprintf (buf, "%ld", n); > if (m != 0) > sprintf (buf + l, ".%03ld", m); > return (buf); That looks overly complex to me. Can you please check if this patch fixes the problem for your test cases, too: >From 963e7db81379225b78bfac0d7457300c86d6b4d6 Mon Sep 17 00:00:00 2001 From: Wolfgang Denk <[EMAIL PROTECTED]> Date: Tue, 21 Oct 2008 15:53:51 +0200 Subject: [PATCH] Fix strmhz(): avoid printing negative fractions Signed-off-by: Wolfgang Denk <[EMAIL PROTECTED]> --- lib_generic/strmhz.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib_generic/strmhz.c b/lib_generic/strmhz.c index 342cf2b..d6da1d1 100644 --- a/lib_generic/strmhz.c +++ b/lib_generic/strmhz.c @@ -27,7 +27,7 @@ char *strmhz (char *buf, long hz) long l, n; long m; - n = DIV_ROUND(hz, 1000000L); + n = DIV_ROUND(hz, 1000) / 1000L; l = sprintf (buf, "%ld", n); hz -= n * 1000000L; -- 1.5.5.1 Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [EMAIL PROTECTED] Good manners are the settled medium of social, as specie is of commercial, life; returns are equally expected for both. - Lord Chesterfield _Letters to his Son_, 25 December 1753 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot