public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] improved strmhz()
@ 2008-10-21 12:44 Ilko Iliev
  2008-10-21 13:55 ` Wolfgang Denk
  0 siblings, 1 reply; 8+ messages in thread
From: Ilko Iliev @ 2008-10-21 12:44 UTC (permalink / raw)
  To: u-boot

This patch prevents the displaying of results like this:
hz = 1999170000
buf = "200.-83"

Signed-off-by: Ilko Iliev <iliev@ronetix.at>

index 342cf2b..981a75a 100644
--- 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);

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-10-22  7:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-21 12:44 [U-Boot] [PATCH] improved strmhz() Ilko Iliev
2008-10-21 13:55 ` Wolfgang Denk
2008-10-21 14:11   ` Ilko Iliev
2008-10-21 16:54   ` Kumar Gala
2008-10-21 17:07     ` Jerry Van Baren
2008-10-21 17:38     ` Mike Frysinger
2008-10-21 19:15     ` Wolfgang Denk
2008-10-22  7:03       ` Stefan Roese

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox