summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-05-06 15:19:25 +0000
committerAndrew Tridgell <tridge@samba.org>2001-05-06 15:19:25 +0000
commit9074322761b4bbd26ea7c3860af992bf8a845758 (patch)
treee6157369c93b80300e39d6f7218ee505c82fd065
parent289b92de513aa1edce6246a1ceac23e72e81d979 (diff)
downloadsamba-9074322761b4bbd26ea7c3860af992bf8a845758.tar.gz
samba-9074322761b4bbd26ea7c3860af992bf8a845758.tar.bz2
samba-9074322761b4bbd26ea7c3860af992bf8a845758.zip
replace modf so we don't need the math library
(This used to be commit 79c0d24a3092098d3d8e58ebe07cf61db7d898e5)
-rw-r--r--source3/lib/snprintf.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c
index 3edb50c6ad..0a52e1762b 100644
--- a/source3/lib/snprintf.c
+++ b/source3/lib/snprintf.c
@@ -71,7 +71,6 @@
#endif
#include <sys/types.h>
#include <stdarg.h>
-#include <math.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -551,6 +550,42 @@ static LLONG ROUND(LDOUBLE value)
return intpart;
}
+/* a replacement for modf that doesn't need the math library. Should
+ be portable, but slow */
+static double my_modf(double x0, double *iptr)
+{
+ int i;
+ long l;
+ double x = x0;
+ double f = 1.0;
+
+ for (i=0;i<100;i++) {
+ l = (long)x;
+ if (l <= (x+1) && l >= (x-1)) break;
+ x *= 0.1;
+ f *= 10.0;
+ }
+
+ if (i == 100) {
+ /* yikes! the number is beyond what we can handle. What do we do? */
+ (*iptr) = 0;
+ return 0;
+ }
+
+ if (i != 0) {
+ double i2;
+ double ret;
+
+ ret = my_modf(x0-l*f, &i2);
+ (*iptr) = l*f + i2;
+ return ret;
+ }
+
+ (*iptr) = l;
+ return x - (*iptr);
+}
+
+
static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags)
{
@@ -608,7 +643,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
*/
temp = ufvalue;
- modf(temp, &intpart);
+ my_modf(temp, &intpart);
fracpart = ROUND((POW10(max)) * (ufvalue - intpart));
@@ -621,7 +656,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
/* Convert integer part */
do {
temp = intpart;
- modf (intpart*0.1, &intpart);
+ my_modf(intpart*0.1, &intpart);
temp = temp*0.1;
index = (int) ((temp -intpart +0.05)* 10.0);
/* index = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */
@@ -637,7 +672,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
{
do {
temp = fracpart;
- modf (fracpart*0.1, &fracpart);
+ my_modf(fracpart*0.1, &fracpart);
temp = temp*0.1;
index = (int) ((temp -fracpart +0.05)* 10.0);
/* index = (int) ((((temp/10) -fracpart) +0.05) *10); */