OSSP CVS Repository

ossp - Difference in ossp-pkg/str/str_format.c versions 1.28 and 1.29
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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]) {

CVSTrac 2.0.1