You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Rajith Attapattu (JIRA)" <qp...@incubator.apache.org> on 2010/07/28 04:17:17 UTC
[jira] Created: (QPID-2766) string to double conversion results in
questionable precision
string to double conversion results in questionable precision
-------------------------------------------------------------
Key: QPID-2766
URL: https://issues.apache.org/jira/browse/QPID-2766
Project: Qpid
Issue Type: Bug
Components: Java Client
Affects Versions: 0.6
Reporter: Rajith Attapattu
Assignee: Rajith Attapattu
Priority: Minor
Fix For: 0.7
The following test:
public void testString2Double_1() {
try {
Message message = senderSession.createMessage();
message.setStringProperty("pi", "3.14159");
assertEquals(3.14159, message.getDoubleProperty("pi"),0);
} catch (JMSException e) {
fail(e);
}
}
Fails with:
junit.framework.AssertionFailedError: expected:<3.14159> but
was:<3.141590118408203>
This appears to be because the client ends up doing the equivalent of
Double.valueOf(Float.valueOf(value)) when doing string to double conversion
rather than the more direct Double.valueOf(value).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
[jira] Commented: (QPID-2766) string to double conversion results
in questionable precision
Posted by "Robbie Gemmell (JIRA)" <qp...@incubator.apache.org>.
[ https://issues.apache.org/jira/browse/QPID-2766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12893140#action_12893140 ]
Robbie Gemmell commented on QPID-2766:
--------------------------------------
Whilst I agree with the reason for making it I dont think the change made is entirely correct as it opens us to violating the JMS spec for property type conversion, since it will now first convert all property types (except Double obviously) to a String and then on to a Double. Only Floats, Doubles, and Strings are allowed to be read back as a Double value, everything else should throw a MessageFormatException. I would suggest the change should be something more along the lines of:
if(o instanceof Double)
{
return ((Double)o).doubleValue();
}
+ else if(o instanceof String)
+ {
+ return Double.valueOf((String) o);
+ }
else
{
try
{
return Double.valueOf(getFloatProperty(propertyName));
In looking at this I have also come to notice that the 0-10 message property handling (do we really need to have seperate handler code for 0-8/9 and 0-10 for all of this?) seems to improperly convert String properties into short, int, and long by delegating the conversion down to the getByteProperty() method which then restricts it to using Byte.valueof(), which is rarely going to work correctly. Ive raised that as QPID-2770.
> string to double conversion results in questionable precision
> -------------------------------------------------------------
>
> Key: QPID-2766
> URL: https://issues.apache.org/jira/browse/QPID-2766
> Project: Qpid
> Issue Type: Bug
> Components: Java Client
> Affects Versions: 0.6
> Reporter: Rajith Attapattu
> Assignee: Rajith Attapattu
> Priority: Minor
> Fix For: 0.7
>
>
> The following test:
> public void testString2Double_1() {
> try {
> Message message = senderSession.createMessage();
> message.setStringProperty("pi", "3.14159");
> assertEquals(3.14159, message.getDoubleProperty("pi"),0);
> } catch (JMSException e) {
> fail(e);
> }
> }
> Fails with:
> junit.framework.AssertionFailedError: expected:<3.14159> but
> was:<3.141590118408203>
> This appears to be because the client ends up doing the equivalent of
> Double.valueOf(Float.valueOf(value)) when doing string to double conversion
> rather than the more direct Double.valueOf(value).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org
[jira] Commented: (QPID-2766) string to double conversion results
in questionable precision
Posted by "Rajith Attapattu (JIRA)" <qp...@incubator.apache.org>.
[ https://issues.apache.org/jira/browse/QPID-2766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12893290#action_12893290 ]
Rajith Attapattu commented on QPID-2766:
----------------------------------------
Thanks for catching this, I have fixed it.
> string to double conversion results in questionable precision
> -------------------------------------------------------------
>
> Key: QPID-2766
> URL: https://issues.apache.org/jira/browse/QPID-2766
> Project: Qpid
> Issue Type: Bug
> Components: Java Client
> Affects Versions: 0.6
> Reporter: Rajith Attapattu
> Assignee: Rajith Attapattu
> Priority: Minor
> Fix For: 0.7
>
>
> The following test:
> public void testString2Double_1() {
> try {
> Message message = senderSession.createMessage();
> message.setStringProperty("pi", "3.14159");
> assertEquals(3.14159, message.getDoubleProperty("pi"),0);
> } catch (JMSException e) {
> fail(e);
> }
> }
> Fails with:
> junit.framework.AssertionFailedError: expected:<3.14159> but
> was:<3.141590118408203>
> This appears to be because the client ends up doing the equivalent of
> Double.valueOf(Float.valueOf(value)) when doing string to double conversion
> rather than the more direct Double.valueOf(value).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org