Project

Profile

Help

clarification xs:float(-0.0), saxon 8.1

Added by Anonymous about 19 years ago

Legacy ID: #3122043 Legacy Poster: Jamie Martin (jameison)

in saxon 8.1 i believe that the behavior of double/float for negative zero (-0.0) and zero (0.0) may not be quite right for java.util.Comparable (though i'm not sure and this is a bit of an abstruse topic). if i read the xpath 2.0 spec correctly, it seems it deviates from xml schema and supports ieee floating points fully (see http://www.w3.org/TR/2005/WD-xpath-functions-20050404/#d1e1156). given this, in Saxon i would expect that -0.0.compareTo(0.0) != 0 and this is in fact what java does but not what Saxon does. to put it another way, i would expect the ordering of negative zero and zero to be well defined. looking at Saxon's net.sf.saxon.value.NumericValue.compareTo(), the reason for this behavior is quite clear and could very easily be changed. not sure if this is a bug because i'm not exactly sure what the XPath spec is saying here, but given that various numeric functions behave differently on -0.0 and 0.0, one would might expect compareTo to behave as java does. this should manifest itself by the following returning false: <doc><float>0.0</float><doc> /doc[float > xs:float(-0.0)] thanks. -jamie


Replies (3)

Please register to reply

RE: clarification xs:float(-0.0), saxon 8.1 - Added by Anonymous about 19 years ago

Legacy ID: #3122172 Legacy Poster: Michael Kay (mhkay)

You're right that this is an abstruse topic. However, XPath is explicit that negative zero and positive zero compare equal. See section 6.3.1 of "Functions and Operators": http://www.w3.org/TR/xpath-functions/#func-numeric-equal

RE: clarification xs:float(-0.0), saxon 8.1 - Added by Anonymous about 19 years ago

Legacy ID: #3124203 Legacy Poster: Jamie Martin (jameison)

agree that negative zero and positive zero equal one another in XPath, that is clearly stated (and in other standards). the question is whether they sort the same and the question is what is the result of max({-0.0, 0.0}). it would be odd for max({-0.0, 0.0}) = -0.0 or to be order defined, but i believe that this is what Saxon is doing. i'm not sure if this is specified in IEEE or what, but it certainly seems odd when one considers that -0.0 and 0.0 represent different numbers and do indeed have a clear ordering. would you have a suggestion as to an appropriate way to raise this to the xpath standards group for clarification?

RE: clarification xs:float(-0.0), saxon 8.1 - Added by Anonymous about 19 years ago

Legacy ID: #3124223 Legacy Poster: Michael Kay (mhkay)

You can raise this as a comment on the specs if you like (the status section tells you how), but I doubt you'll get very far with it. Sorting and functions such as min and max are defined in terms of the lt/eq family of operators, so if two values are equal from the point of view of eq, they are also equal from the point of view of min/max and sorting. MK

    (1-3/3)

    Please register to reply