OSSP CVS Repository

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

Check-in Number: 4531
Date: 2004-Apr-23 12:05:58 (local)
2004-Apr-23 10:05:58 (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/cfg/ChangeLog      1.7 -> 1.8     9 inserted, 0 deleted
ossp-pkg/cfg/cfg_fmt.c      1.4 -> 1.5     22 inserted, 4 deleted

ossp-pkg/cfg/ChangeLog 1.7 -> 1.8

--- ChangeLog    2003/11/10 19:15:54     1.7
+++ ChangeLog    2004/04/23 10:05:58     1.8
@@ -8,6 +8,15 @@
 
   CHANGELOG
 
+ Changes between 0.9.2 and 0.9.3 (10-Nov-2003 to 23-Apr-2004):
+
+   *) Import change introduced in OSSP l2 0.9.7:
+      Replace modf(3) calls in cfg_fmt.c with a hand-crafted
+      inlined cfg_fmt_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.1 and 0.9.2 (10-Nov-2003 to 10-Nov-2003)
 
    *) Upgraded build environment to GNU libtool 1.5 and


ossp-pkg/cfg/cfg_fmt.c 1.4 -> 1.5

--- cfg_fmt.c    2003/01/06 11:17:43     1.4
+++ cfg_fmt.c    2004/04/23 10:05:58     1.5
@@ -96,7 +96,6 @@
 #include <stdarg.h>
 #include <string.h>
 #include <ctype.h>
-#include <math.h>
 
 #include "cfg_fmt.h"
 
@@ -162,6 +161,25 @@
 #define cfg_fmt_fcvt(arg,ndigits,decpt,sign,buf) \
         cfg_fmt_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
+cfg_fmt_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 *
 cfg_fmt_cvt(
     double arg,
@@ -184,14 +202,14 @@
         *sign = TRUE;
         arg = -arg;
     }
-    arg = modf(arg, &fi);
+    arg = cfg_fmt_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 = cfg_fmt_modf(fi / 10, &fi);
             *--p1 = (int)((fj + .03) * 10) + '0';
             r2++;
         }
@@ -214,7 +232,7 @@
     }
     while (p <= p1 && p < &buf[NDIG]) {
         arg *= 10;
-        arg = modf(arg, &fj);
+        arg = cfg_fmt_modf(arg, &fj);
         *p++ = (int) fj + '0';
     }
     if (p1 >= &buf[NDIG]) {

CVSTrac 2.0.1