[U-Boot] [PATCH] improved strmhz()
Ilko Iliev
iliev at ronetix.at
Tue Oct 21 16:11:34 CEST 2008
Wolfgang Denk wrote:
> Dear Ilko Iliev,
>
> In message <48FDCEB6.9040206 at ronetix.at> 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:
>
Yes, it works.
--
Mit freundlichen Grüßen/With best regards,
Ilko Iliev
Ronetix Development Tools GmbH
Waidhausenstrasse 13/5
1140 Vienna, Austria
Tel: +43 1 956 3138
Tel: +43 720 500 315
Fax: +43 1 8174 955 3464
E-Mail: iliev at ronetix.at
Web: www.ronetix.at
VAT: ATU63916016
Ronetix GmbH - 1140 Vienna - Geschäftsführer: Ilko Iliev
Registergericht: HG Vienna, FN 304979z
More information about the U-Boot
mailing list