diff options
author | Simo Sorce <idra@samba.org> | 2002-04-16 22:38:04 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2002-04-16 22:38:04 +0000 |
commit | a32940d53e127bb7d46a4d46d24a53b17a23a8a4 (patch) | |
tree | 9c0338a3050be26fdc6a5446ca55b1d0945de44c /source3/lib | |
parent | eebe9749e0f9d287e7320314b958260bd5a448be (diff) | |
download | samba-a32940d53e127bb7d46a4d46d24a53b17a23a8a4.tar.gz samba-a32940d53e127bb7d46a4d46d24a53b17a23a8a4.tar.bz2 samba-a32940d53e127bb7d46a4d46d24a53b17a23a8a4.zip |
Fix incorrect zpadlen handling in fmtfp.
Thanks to Ollie Oldham <ollie.oldham@metro-optix.com> for spotting it.
few mods to make it easier to compile the tests.
addedd the "Ollie" test to the floating point ones.
(This used to be commit 415f9d92bc0a37d38b81a653a4b4c5f0fefa2fe8)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/snprintf.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/source3/lib/snprintf.c b/source3/lib/snprintf.c index 9a9dcdbae1..3034dfaaf6 100644 --- a/source3/lib/snprintf.c +++ b/source3/lib/snprintf.c @@ -57,6 +57,12 @@ #ifndef NO_CONFIG_H /* for some tests */ #include "config.h" +#else +#define NULL 0 +#endif + +#ifdef TEST_SNPRINTF /* need math library headers for testing */ +#include <math.h> #endif #ifdef HAVE_STRING_H @@ -656,9 +662,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, /* Convert integer part */ do { - temp = intpart; - my_modf(intpart*0.1, &intpart); - temp = temp*0.1; + temp = intpart*0.1; + my_modf(temp, &intpart); index = (int) ((temp -intpart +0.05)* 10.0); /* index = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ /* printf ("%llf, %f, %x\n", temp, intpart, index); */ @@ -672,9 +677,8 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (fracpart) { do { - temp = fracpart; - my_modf(fracpart*0.1, &fracpart); - temp = temp*0.1; + temp = fracpart*0.1; + my_modf(temp, &fracpart); index = (int) ((temp -fracpart +0.05)* 10.0); /* index = (int) ((((temp/10) -fracpart) +0.05) *10); */ /* printf ("%lf, %lf, %ld\n", temp, fracpart, index); */ @@ -726,14 +730,14 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (max > 0) { dopr_outch (buffer, currlen, maxlen, '.'); + while (zpadlen > 0) { + dopr_outch (buffer, currlen, maxlen, '0'); + --zpadlen; + } + while (fplace > 0) dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); } - - while (zpadlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --zpadlen; - } while (padlen < 0) { dopr_outch (buffer, currlen, maxlen, ' '); @@ -853,7 +857,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) NULL }; double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, - 0.9996, 1.996, 4.136, 0}; + 0.9996, 1.996, 4.136, 5.030201, 0}; char *int_fmt[] = { "%-1.5d", "%1.5d", @@ -948,8 +952,10 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) { double v0 = 0.12345678901234567890123456789012345678901; for (x=0; x<100; x++) { - snprintf(buf1, sizeof(buf1), "%1.1f", v0*pow(10, x)); - sprintf(buf2, "%1.1f", v0*pow(10, x)); + double p = pow(10, x); + double r = v0*p; + snprintf(buf1, sizeof(buf1), "%1.1f", r); + sprintf(buf2, "%1.1f", r); if (strcmp(buf1, buf2)) { printf("we seem to support %d digits\n", x-1); break; |