]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: use local sqrt() implemenation
authorKarel Zak <kzak@redhat.com>
Thu, 13 Oct 2022 08:25:25 +0000 (10:25 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 25 Oct 2022 09:11:06 +0000 (11:11 +0200)
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 <kzak@redhat.com>
libsmartcols/src/Makemodule.am
libsmartcols/src/calculate.c

index db3e68528fae94dc08bfc4af62fe884651dcdba5..2bb19fdbde0a991b979cbcdfcdbd779dd0f6f033 100644 (file)
@@ -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) \
index b55d6c2ec97d09c260469c4021f0e2faa6511c62..b500d33945ac0bddad33074cdf1d7f464d3b9c05 100644 (file)
@@ -1,8 +1,6 @@
 #include "smartcolsP.h"
 #include "mbsalign.h"
 
-#include <math.h>
-
 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",