From dd299a9cf6e93e2b8b29dd14edab6caaf156a79a Mon Sep 17 00:00:00 2001 From: hniksic Date: Tue, 29 Mar 2005 12:03:42 -0800 Subject: [PATCH] [svn] Slightly better handling of negative numbers in numdigit. --- src/ChangeLog | 4 ++++ src/utils.c | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d306c41b..9253d316 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2005-03-29 Hrvoje Niksic + + * utils.c (numdigit): More correct handling of negative numbers. + 2005-03-21 Hrvoje Niksic * http.c (gethttp): Print the human-readable size. diff --git a/src/utils.c b/src/utils.c index 2e8524ed..50de97c6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1368,17 +1368,16 @@ human_readable (wgint n) return NULL; /* unreached */ } -/* Count the digits in an integer number. */ +/* Count the digits in the provided number. Used to allocate space + when printing numbers. */ + int numdigit (wgint number) { int cnt = 1; if (number < 0) - { - number = -number; - ++cnt; - } - while ((number /= 10) > 0) + ++cnt; /* accomodate '-' */ + while ((number /= 10) != 0) ++cnt; return cnt; } @@ -1468,8 +1467,8 @@ numdigit (wgint number) #endif /* Print NUMBER to BUFFER in base 10. This is equivalent to - `sprintf(buffer, "%lld", (long long) number)', only much faster and - portable to machines without long long. + `sprintf(buffer, "%lld", (long long) number)', only typically much + faster and portable to machines without long long. The speedup may make a difference in programs that frequently convert numbers to strings. Some implementations of sprintf, -- 2.39.2