summaryrefslogtreecommitdiff
path: root/regress/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2017-05-17 20:28:36 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2017-05-17 20:28:36 +0000
commit6d902117b32aa931e7c585361e82ee07d36e31f4 (patch)
tree06c78304b1dc04910907e66f1f50bde74eae4f41 /regress/lib/libc
parentd08590301ef618ae0f92820f480060fe3ef981bb (diff)
Approximate nlgn instead of using libm. The same approximation may
be used in qsort.c in a later commit.
Diffstat (limited to 'regress/lib/libc')
-rw-r--r--regress/lib/libc/qsort/Makefile4
-rw-r--r--regress/lib/libc/qsort/qsort_test.c14
2 files changed, 8 insertions, 10 deletions
diff --git a/regress/lib/libc/qsort/Makefile b/regress/lib/libc/qsort/Makefile
index d3c4e2baa22..9062e26f956 100644
--- a/regress/lib/libc/qsort/Makefile
+++ b/regress/lib/libc/qsort/Makefile
@@ -1,9 +1,7 @@
-# $OpenBSD: Makefile,v 1.1 2017/05/17 14:47:06 millert Exp $
+# $OpenBSD: Makefile,v 1.2 2017/05/17 20:28:35 millert Exp $
PROG= qsort_test
CFLAGS+=-Wall
-LDADD+= -lm
-DPADD+= ${LIBM}
qsort-regress: ${PROG}
./${PROG}
diff --git a/regress/lib/libc/qsort/qsort_test.c b/regress/lib/libc/qsort/qsort_test.c
index b23f3e61905..3b36eb06b49 100644
--- a/regress/lib/libc/qsort/qsort_test.c
+++ b/regress/lib/libc/qsort/qsort_test.c
@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
-#include <math.h>
#include <err.h>
/*
@@ -235,16 +234,17 @@ run_tests(int m, int n)
{
int *x, *y, *z;
int ret = 0;
- double nlgn;
+ int idx, nlgn = 0;
enum distribution dist;
/*
- * The expected number of compares is A * n * log2(n)
- * where A is between 1 and 2. If A is greater than 1.5
- * we'll print a warning. If A is greater than 10 we
- * abort the test since qsort has probably gone quadratic.
+ * We expect A*n*lg(n) compares where A is between 1 and 2.
+ * For A > 1.5, print a warning.
+ * For A > 10 abort the test since qsort has probably gone quadratic.
*/
- nlgn = n * log2(n);
+ for (idx = n - 1; idx > 0; idx >>= 1)
+ nlgn++;
+ nlgn *= n;
max_compares = nlgn * 1.5;
abrt_compares = nlgn * 10;