From e01fdc3dba36336bf4acbbf5ea1e3f7ac9c6fb6a Mon Sep 17 00:00:00 2001
From: Dan McGee <dan@archlinux.org>
Date: Thu, 2 Feb 2012 22:36:46 -0600
Subject: 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>
---
 src/pacman/util.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

(limited to 'src')

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;
 	}
 
-- 
cgit v1.2.3-2-g168b