From: Karel Zak Date: Thu, 13 Oct 2022 08:25:25 +0000 (+0200) Subject: libsmartcols: use local sqrt() implemenation X-Git-Tag: v2.39-rc1~460 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee4cab98def0f263a3929bb9b8a2282c00ddacaf;p=thirdparty%2Futil-linux.git libsmartcols: use local sqrt() implemenation We do not need any powerful and precise sqrt implementation, so let's use local code rather than depend on an external library. Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/Makemodule.am b/libsmartcols/src/Makemodule.am index db3e68528f..2bb19fdbde 100644 --- a/libsmartcols/src/Makemodule.am +++ b/libsmartcols/src/Makemodule.am @@ -23,7 +23,7 @@ libsmartcols_la_SOURCES= \ libsmartcols/src/walk.c \ libsmartcols/src/init.c -libsmartcols_la_LIBADD = $(LDADD) $(MATH_LIBS) libcommon.la +libsmartcols_la_LIBADD = $(LDADD) libcommon.la libsmartcols_la_CFLAGS = \ $(AM_CFLAGS) \ diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index b55d6c2ec9..b500d33945 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -1,8 +1,6 @@ #include "smartcolsP.h" #include "mbsalign.h" -#include - static void dbg_column(struct libscols_table *tb, struct libscols_column *cl) { struct libscols_wstat *st; @@ -87,6 +85,17 @@ static int walk_count_cell_width(struct libscols_table *tb, return count_cell_width(tb, ln, cl, (struct ul_buffer *) data); } +static double sqrtroot(double num) +{ + double tmp = 0, sq = num / 2; + + while (sq != tmp){ + tmp = sq; + sq = (num / tmp + tmp) / 2; + } + return sq; +} + static void count_column_deviation(struct libscols_table *tb, struct libscols_column *cl) { struct libscols_wstat *st; @@ -124,7 +133,7 @@ static void count_column_deviation(struct libscols_table *tb, struct libscols_co } variance = st->width_sqr_sum / (n - 1); - st->width_deviation = sqrt(variance); + st->width_deviation = sqrtroot(variance); } DBG(COL, ul_debugobj(cl, "%15s avg=%g, deviation=%g",