All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilko Iliev <iliev@ronetix.at>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] improved strmhz()
Date: Tue, 21 Oct 2008 14:44:38 +0200	[thread overview]
Message-ID: <48FDCEB6.9040206@ronetix.at> (raw)

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);

             reply	other threads:[~2008-10-21 12:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-21 12:44 Ilko Iliev [this message]
2008-10-21 13:55 ` [U-Boot] [PATCH] improved strmhz() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48FDCEB6.9040206@ronetix.at \
    --to=iliev@ronetix.at \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.