Skip to content

Commit 6386c85

Browse files
author
giraffedata
committed
Release 1.17.08
git-svn-id: https://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/advanced@1688 adbb7d4b-a73a-0410-a071-c5f57c452bd4
1 parent 4ce8f70 commit 6386c85

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/double.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <float.h>
44

55
#include "xmlrpc-c/util.h"
6+
#include "xmlrpc-c/util_int.h"
67

78
#include "double.h"
89

@@ -58,6 +59,23 @@ digitChar(unsigned int const digitValue) {
5859

5960

6061

62+
static unsigned int
63+
leadDigit(double const arg,
64+
double const precision) {
65+
/*----------------------------------------------------------------------------
66+
Assuming 'arg' has one digit before the decimal point (which may be zero),
67+
return that digit.
68+
69+
We assume the precision of 'arg' is plus or minus 'precision', and bias our
70+
estimation of the first digit up. We do that bias in order to bias toward
71+
shorter decimal ciphers: It's cleaner to consider 2.9999999 to be 3 than to
72+
consider 3 to be 2.999999.
73+
-----------------------------------------------------------------------------*/
74+
return MIN(9, (unsigned int)(arg + precision));
75+
}
76+
77+
78+
6179
static void
6280
floatWhole(double const value,
6381
buffer * const formattedP,
@@ -88,7 +106,8 @@ floatWhole(double const value,
88106
*/
89107
leastValue = 0;
90108
} else
91-
leastValue = (unsigned int)(value - nonLeastAmount * 10);
109+
leastValue = leadDigit(value - nonLeastAmount * 10,
110+
nonLeastPrecision * 10);
92111

93112
bufferConcat(formattedP, digitChar(leastValue));
94113

@@ -120,7 +139,7 @@ floatFractionPart(double const value,
120139
unsigned int digitValue;
121140

122141
d *= 10;
123-
digitValue = (unsigned int) d;
142+
digitValue = leadDigit(d, precision);
124143

125144
d -= digitValue;
126145

@@ -154,7 +173,7 @@ floatFraction(double const value,
154173
precision = DBL_EPSILON;
155174

156175
while (d > precision) {
157-
unsigned int const digitValue = (unsigned int) d;
176+
unsigned int const digitValue = leadDigit(d, precision);
158177

159178
bufferConcat(formattedP, digitChar(digitValue));
160179

src/test/serialize_value.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ test_serialize_double(void) {
173173
testOneDouble(1);
174174
testOneDouble(0.3);
175175
testOneDouble(4.9);
176+
testOneDouble(9.9999999);
176177
testOneDouble(-8);
177178
testOneDouble(-.7);
178179
testOneDouble(-2.5);

version.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
###############################################################################
99
XMLRPC_MAJOR_RELEASE = 1
1010
XMLRPC_MINOR_RELEASE = 17
11-
XMLRPC_POINT_RELEASE = 7
11+
XMLRPC_POINT_RELEASE = 8

0 commit comments

Comments
 (0)