You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Matt Mower <ma...@evectors.com> on 2004/05/27 12:13:35 UTC

Problem with doubles

Hi folks,

I'm using the Apache XML-RPC 1.2-b1 library to communicate with a
process running on Frontier however the library seems to be improperly
encoding doubles.

According to the spec[1] only standard decimal representation is supported:

> At this time, only decimal point notation is allowed, a plus or a
> minus, followed by any number of numeric characters, followed by a
> period and any number of numeric characters.

However I am occasionally seeing results being passed using scientific
notification:

> <value><double>2.059538383036852E-4</double></value>

my Java code is doing:

> Vector result = new Vector( 2 );
> result.add( new Integer( doc.get( "id" ) ) );
> result.add( new Double( hits.score( i ) ) );

to send doubles back to Frontier.

I didn't find anything in the bug database. I also tried the older v1.1
library with the same result. Is it a known problem?

Many thanks,

Matt

[1] http://www.xmlrpc.com/spec/

-- 
Evectors Software
Email:matt@evectors.com  Web:http://www.evectors.com
Tel:+44-(0)7977-076-709  Blog:http://matt.blogs.it/



Re: Problem with doubles

Posted by Matt Mower <ma...@evectors.com>.
Daniel Rall wrote:

>  > which does not conform to the spec
> 
> That makes it sound like we shouldn't support scientific notation at 
> all. Unfortunately, that means breaking backwards compatibility with our 
> own bugs. Ideally, we'd output in the spec-complient format, and support 
> input of doubles in scientific notation in a deprecated fashion for a 
> few releases.
> 

I guess whether you consider *supporting* scientific notation a bug 
depends upon whether you see it as encouraging spec incompatibility.  I 
think the approach you suggest sounds just fine.

Regards,

Matt

-- 
Evectors Software
Email:matt@evectors.com  Web:http://www.evectors.com
Tel:+44-(0)7977-076-709  Blog:http://matt.blogs.it/

Re: Problem with doubles

Posted by Daniel Rall <dl...@collab.net>.
Matt Mower wrote:
> Hi Daniel,
> 
> Thanks for responding.

Of course!  I don't have much time to spend on this project these days, so 
generally lag quite a bit behind the list.

> Daniel L. Rall wrote:
> 
>> Matt, I'm very interested in integrating your changes.  Please send a 
>> patch and associated change log which includes information from your 
>> message below, but is tied to specific class and member names.
> 
> I'm not clear on how I would produce such a patch.  Is there a page 
> somewhere than can enlighten me?

http://jakarta.apache.org/site/source.html#Patches

A patch against either the tip of HEAD and/or the XMLRPC_1_2_BRANCH would be 
preferred.  Let me know if I can help clarify things any further.

>> How were you thinking to make it configurable?
> 
> If the default format is well chosen so that only people exchanging 
> precise scientific data need to bother changing it then probably a 
> system property.

Hmm.  On June 16th, you mentioned:

> a problem with Apache XML-RPC encoding Doubles using scientific notation,
 > which does not conform to the spec

That makes it sound like we shouldn't support scientific notation at all. 
Unfortunately, that means breaking backwards compatibility with our own bugs. 
Ideally, we'd output in the spec-complient format, and support input of doubles 
in scientific notation in a deprecated fashion for a few releases.

Re: Problem with doubles

Posted by Matt Mower <ma...@evectors.com>.
Hi Daniel,

Thanks for responding.

Daniel L. Rall wrote:
> Matt, I'm very interested in integrating your changes.  Please send a 
> patch and associated change log which includes information from your 
> message below, but is tied to specific class and member names.
> 

I'm not clear on how I would produce such a patch.  Is there a page 
somewhere than can enlighten me?

> How were you thinking to make it configurable?
> 

If the default format is well chosen so that only people exchanging 
precise scientific data need to bother changing it then probably a 
system property.

Regards,

Matt

-- 
Evectors Software
Email:matt@evectors.com  Web:http://www.evectors.com
Tel:+44-(0)7977-076-709  Blog:http://matt.blogs.it/

Re: Problem with doubles

Posted by "Daniel L. Rall" <dl...@finemaltcoding.com>.
Matt, I'm very interested in integrating your changes.  Please send a patch 
and associated change log which includes information from your message below, 
but is tied to specific class and member names.

How were you thinking to make it configurable?

Matt Mower wrote:
> Matt Mower wrote:
> 
>> Hi folks,
>>
>> I'm using the Apache XML-RPC 1.2-b1 library to communicate with a
>> process running on Frontier however the library seems to be improperly
>> encoding doubles.
>>
>> According to the spec[1] only standard decimal representation is 
>> supported:
>>
>>> At this time, only decimal point notation is allowed, a plus or a
>>> minus, followed by any number of numeric characters, followed by a
>>> period and any number of numeric characters.
>>
>>
>>
>> However I am occasionally seeing results being passed using scientific
>> notification:
>>
>>> <value><double>2.059538383036852E-4</double></value>
>>
>>
> 
> Did I report this to the right place?
> 
> I've done a little digging and the problem appears to be in:
> 
>     org.apache.xmlrpc.XmlWriter#writeObject( Object obj )
> 
> where it does:
> 
>         else if (obj instanceof Double || obj instanceof Float)
>         {
>             startElement("double");
>             write(obj.toString());
>             endElement("double");
>         }
> 
> My suggested fix is to add a DecimalFormat instance to the class (it 
> appears to be thread safe so could be added as a static like dateTool) 
> and use:
> 
>         else if (obj instanceof Double || obj instanceof Float)
>         {
>             startElement("double");
>             write( decimalFormat.format( obj ) );
>             endElement("double");
>         }
> 
> I've made this fix to my local copy and, in my limited tests, it seems 
> to work fine.
> 
> There is an issue about precision since you have to specify a pattern to 
> the DecimalFormat.  I rather arbitrarily used 
> "0.0#######################" which was good enough for my purposes (i.e. 
> I no longer get errors) but probably this is the kind of thing that 
> should be configurable.
> 
> Any thoughts?


Re: Problem with doubles

Posted by Matt Mower <ma...@evectors.com>.
Matt Mower wrote:
> Hi folks,
> 
> I'm using the Apache XML-RPC 1.2-b1 library to communicate with a
> process running on Frontier however the library seems to be improperly
> encoding doubles.
> 
> According to the spec[1] only standard decimal representation is supported:
> 
>> At this time, only decimal point notation is allowed, a plus or a
>> minus, followed by any number of numeric characters, followed by a
>> period and any number of numeric characters.
> 
> 
> However I am occasionally seeing results being passed using scientific
> notification:
> 
>> <value><double>2.059538383036852E-4</double></value>
> 

Did I report this to the right place?

I've done a little digging and the problem appears to be in:

	org.apache.xmlrpc.XmlWriter#writeObject( Object obj )

where it does:

         else if (obj instanceof Double || obj instanceof Float)
         {
             startElement("double");
             write(obj.toString());
             endElement("double");
         }

My suggested fix is to add a DecimalFormat instance to the class (it 
appears to be thread safe so could be added as a static like dateTool) 
and use:

         else if (obj instanceof Double || obj instanceof Float)
         {
             startElement("double");
             write( decimalFormat.format( obj ) );
             endElement("double");
         }

I've made this fix to my local copy and, in my limited tests, it seems 
to work fine.

There is an issue about precision since you have to specify a pattern to 
the DecimalFormat.  I rather arbitrarily used 
"0.0#######################" which was good enough for my purposes (i.e. 
I no longer get errors) but probably this is the kind of thing that 
should be configurable.

Any thoughts?

Matt

-- 
Evectors Software
Email:matt@evectors.com  Web:http://www.evectors.com
Tel:+44-(0)7977-076-709  Blog:http://matt.blogs.it/