This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 21619 - wrong results when handeling -0 negativeZero
Summary: wrong results when handeling -0 negativeZero
Status: RESOLVED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 3 & XPath 3 Test Suite (show other bugs)
Version: Working drafts
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: O'Neil Delpratt
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-08 13:09 UTC by Cezar Andrei
Modified: 2013-05-07 16:34 UTC (History)
3 users (show)

See Also:


Attachments

Description Cezar Andrei 2013-04-08 13:09:05 UTC
Test case prod-FLWORExpr/ForExprType010 and prod-OrderByClause/orderBy26 should check for a return value of -0 not 0. The two cases load up the value -0 from an XML document as decimal values and returns it. According to XMLSchema 1.1 http://www.w3.org/TR/xmlschema11-2/#sec-chnum and the note on http://www.w3.org/TR/xpath-functions-30/#numeric-types -0 and 0 are distinct values and should be treated acordingly.


Related is prod-OrderByClause/orderBy29 that returns ($x * -1e0) where $x is -0. Since it doesn't come from "-0" sting or the result of "-" unary opperator it should return just 0 (pozitive zero).
Comment 1 Michael Kay 2013-04-08 13:52:01 UTC
Concerning ForExprType010, the values are decimal rather than double/float, and the type xs:decimal does not have a negative zero in its value space.

Concerning orderBy29, the last result in the sequence is formed by converting "-0" to decimal (giving zero) and then multiplying by the double value -1e0. First the decimal zero is converted to the double (positive) zero, then this is multiplied by double minus one. The IEEE rules are that +0e0 times -1e0 gives negative zero.

So I believe both tests are correct.
Comment 2 Cezar Andrei 2013-04-08 23:37:20 UTC
It's odd that decimal doesn't support -0 while float and double does. The XMLSchema 1.1 it not very clear, defines the value space of decimal by using the value space of integer, while the value space of integer says only: "The ·value space· of integer is the infinite set {...,-2,-1,0,1,2,...}." 

If this means that there is no -0 as a decimal, which means that the test case prod-OrderByClause/orderBy20 and orderBy21 have the wrong result. 

The tests cases parses -0 (from orderData.xml) as a decimal (according to orderData.xsd) and returns it, just like prod-FLWORExpr/ForExprType010 and prod-OrderByClause/orderBy26. But the result is expected as -0.
Comment 3 Michael Kay 2013-04-09 08:44:18 UTC
(In reply to comment #2)
> It's odd that decimal doesn't support -0 while float and double does.

Well, in my view the concept of negative zero is pretty odd to start with, but who are we to argue?
 The
> XMLSchema 1.1 it not very clear, defines the value space of decimal by using
> the value space of integer, while the value space of integer says only: "The
> ·value space· of integer is the infinite set {...,-2,-1,0,1,2,...}." 

I think we can be glad that the XSD designers took a few concepts as given, rather than attempting to formalize the whole system of arithmetic...
> 
> If this means that there is no -0 as a decimal, which means that the test
> case prod-OrderByClause/orderBy20 and orderBy21 have the wrong result. 
> 
I have no idea why these tests include more than one permitted result, but the reason they include -0 in the result is that the query is returning the orderData elements, not their atomized values. However (I think), an implementation is permitted to retain the typed value rather than the string value, and to reconstitute the string value on serialization, and such an implementation could legitimately output <orderData>0</orderData> rather than <orderData>-0</orderData>.
Comment 4 Michael Kay 2013-04-09 08:51:04 UTC
Looking at the history here:

https://www.w3.org/Bugs/Public/show_bug.cgi?id=1997

it's clear that the reason there are alternative results for these tests is to allow for processors that don't validate the input and process it as untyped. We've moved on from there: such processors shouldn't run this test, and the alternative untyped results should therefore be removed.
Comment 5 Sorin Nasoi 2013-04-10 15:16:38 UTC
(In reply to comment #4)
> Looking at the history here:
> 
> https://www.w3.org/Bugs/Public/show_bug.cgi?id=1997
> 
> it's clear that the reason there are alternative results for these tests is
> to allow for processors that don't validate the input and process it as
> untyped. We've moved on from there: such processors shouldn't run this test,
> and the alternative untyped results should therefore be removed.

Please see test set "prod-OrderByClause", test cases "orderBy20" and "orderBy21"

Only accepted results for these test cases are with "-0" (negative zero).
Comment 6 Cezar Andrei 2013-04-10 16:11:12 UTC
I think we all agree that the results for prod-OrderByClause/orderBy20 and orderBy21 should not contain -0. As it stands right now, there are only results that contain -0:

http://dev.w3.org/cvsweb/2011/QT3-test-suite/prod/OrderByClause.xml?rev=1.9;content-type=text%2Fplain

The correct results should only contain 0, without the minus.
Comment 7 Michael Kay 2013-04-10 16:28:01 UTC
>The correct results should only contain 0, without the minus.

No, that's wrong. As I explained in comment 3 these tests are returning the original element from the input XDM instance, which contains the text node "-0".

One *could* justify returning "0" as an alternative, on the theory that 

"If an implementation stores only the typed value of an element, it may use any valid lexical representation of the typed value for the string-value property."

(XDM 3.0 section 6.2.4)
Comment 8 Cezar Andrei 2013-04-10 16:50:49 UTC
The "0" result should be added as an alternate result for processors that store only the typed value.

And as you mentioned in comment #4, the alternate result for processors that don't validate the input should be removed (since they should not run this test).
Comment 9 O'Neil Delpratt 2013-05-01 14:02:03 UTC
Inline with the agreed resolution in comment #8 I have made the changes to the test cases i.e. alternative result, and committed them to cvs.
Comment 10 Sorin Nasoi 2013-05-01 18:18:37 UTC
prod-OrderByClause/orderBy20 and orderBy21 were not fixed.
Comment 11 O'Neil Delpratt 2013-05-07 16:34:28 UTC
(In reply to comment #10)
> prod-OrderByClause/orderBy20 and orderBy21 were not fixed.

Test cases now fixed with additional expected results.