OSSP CVS Repository

ossp - Check-in [4529]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4529
Date: 2004-Apr-23 12:03:09 (local)
2004-Apr-23 10:03:09 (UTC)
User:thl
Branch:
Comment: Replace modf(3) with hand-crafted inlined function to avoid dependency to external libm; see Checkin [4512]
Tickets:
Inspections:
Files:
ossp-pkg/str/ChangeLog      1.46 -> 1.47     9 inserted, 0 deleted
ossp-pkg/str/configure.ac      1.12 -> 1.13     0 inserted, 2 deleted
ossp-pkg/str/str_format.c      1.28 -> 1.29     22 inserted, 3 deleted
ossp-pkg/str/str_p.h      1.21 -> 1.22     0 inserted, 1 deleted

ossp-pkg/str/ChangeLog 1.46 -> 1.47

--- ChangeLog    2004/04/23 09:30:36     1.46
+++ ChangeLog    2004/04/23 10:03:09     1.47
@@ -9,6 +9,15 @@
 
  ChangeLog
 
+ Changes between 0.9.8 and 0.9.9 (17-Feb-2003 to 23-Apr-2004):
+
+   *) Import change introduced in OSSP l2 0.9.7:
+      Replace modf(3) calls in str_format.c with a hand-crafted
+      inlined str_modf() function to avoid dependency to external
+      libm on systems where modf(3) is not part of libc, i.e. Tru64 and
+      QNX. Reported by Karl Vogel.
+      [Thomas Lotterer <thomas@lotterer.net>]
+
  Changes between 0.9.7 and 0.9.8 (01-Apr-2002 to 17-Feb-2003):
  
    *) Added @DEFS@ to $(CFLAGS) in Makefile.in to correctly see things


ossp-pkg/str/configure.ac 1.12 -> 1.13

--- configure.ac 2003/01/06 19:13:47     1.12
+++ configure.ac 2004/04/23 10:03:09     1.13
@@ -29,8 +29,6 @@
 AC_HAVE_FUNCS(memmove memset memcmp memchr)
 AC_HAVE_FUNCS(isnan isinf)
 
-AC_CHECK_FUNC(modf, , AC_CHECK_LIB(m, modf))
-
 AC_CHECK_EXTLIB([Dmalloc], dmalloc, dmalloc_debug, dmalloc.h,
                 [AC_DEFINE(WITH_DMALLOC, 1, [Define to 1 if building with Dmalloc])])
 


ossp-pkg/str/str_format.c 1.28 -> 1.29

--- str_format.c 2003/01/06 19:13:47     1.28
+++ str_format.c 2004/04/23 10:03:09     1.29
@@ -134,6 +134,25 @@
 #define str_fcvt(arg,ndigits,decpt,sign,buf) \
         str_cvt((arg), (ndigits), (decpt), (sign), 0, (buf))
 
+/* inlined modf(3) to avoid dependency to external libm on systems
+   (like Tru64, QNX, etc) where modf(3) is not part of libc. */
+static double
+str_modf(
+    double arg,
+    double *iptr)
+{
+    double fraction;
+    double integral;
+    long trunc;
+
+    trunc = (long)arg;
+    integral = (double)trunc;
+    fraction = arg - integral;
+    if (iptr != NULL)
+        *iptr = integral;
+    return fraction;
+}
+
 static char *
 str_cvt(
     double arg,
@@ -156,14 +175,14 @@
         *sign = TRUE;
         arg = -arg;
     }
-    arg = modf(arg, &fi);
+    arg = str_modf(arg, &fi);
     p1 = &buf[NDIG];
 
     /* Do integer part */
     if (fi != 0) {
         p1 = &buf[NDIG];
         while (fi != 0 && p1 > &buf[0]) {
-            fj = modf(fi / 10, &fi);
+            fj = str_modf(fi / 10, &fi);
             *--p1 = (int)((fj + .03) * 10) + '0';
             r2++;
         }
@@ -186,7 +205,7 @@
     }
     while (p <= p1 && p < &buf[NDIG]) {
         arg *= 10;
-        arg = modf(arg, &fj);
+        arg = str_modf(arg, &fj);
         *p++ = (int) fj + '0';
     }
     if (p1 >= &buf[NDIG]) {


ossp-pkg/str/str_p.h 1.21 -> 1.22

--- str_p.h      2003/01/06 19:13:47     1.21
+++ str_p.h      2004/04/23 10:03:09     1.22
@@ -35,7 +35,6 @@
 #endif
 
 #include <stdlib.h>     /* for malloc, etc. */
-#include <math.h>       /* for modf(3) */
 #include <string.h>     /* ... */
 
 #include "str.h"

CVSTrac 2.0.1