summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-02-02 22:36:46 -0600
committerDan McGee <dan@archlinux.org>2012-02-03 08:56:17 -0600
commite01fdc3dba36336bf4acbbf5ea1e3f7ac9c6fb6a (patch)
treeec848a24dad0b524e4759051d65743e233fdb38b
parente8db984ce5997ffabafab2584fa7f00789ff3afd (diff)
Add simple integer-only pow() implementation
We hardly need the complexity (or slowness) provided by the libm power function; add a super-cheap one that suits our needs and is specialized for the values we plan on passing in. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/util.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 96284a33..14e6f6b7 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -36,7 +36,6 @@
#include <unistd.h>
#include <limits.h>
#include <wchar.h>
-#include <math.h> /* pow */
#ifdef HAVE_TERMIOS_H
#include <termios.h> /* tcflush */
#endif
@@ -989,6 +988,17 @@ static char *pkg_get_location(alpm_pkg_t *pkg)
}
}
+/* a pow() implementation that is specialized for an integer base and small,
+ * positive-only integer exponents. */
+static double simple_pow(int base, int exp)
+{
+ double result = 1.0;
+ for(; exp > 0; exp--) {
+ result *= base;
+ }
+ return result;
+}
+
/** Converts sizes in bytes into human readable units.
*
* @param bytes the size in bytes
@@ -1025,7 +1035,8 @@ double humanize_size(off_t bytes, const char target_unit, int precision,
}
/* fix FS#27924 so that it doesn't display negative zeroes */
- if(precision >= 0 && val < 0.0 && val > (-0.5 / pow(10, precision))) {
+ if(precision >= 0 && val < 0.0 &&
+ val > (-0.5 / simple_pow(10, precision))) {
val = 0.0;
}