-
Notifications
You must be signed in to change notification settings - Fork 25
SPARQL 1.1: test ABS, CEIL, FLOOR, ISNUMERIC and ROUND on xsd:float and xsd:double #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Testing this accurately is harder than usual. Jena's usual comparison of result sets uses a test for same term and, if that fails, a test for same value. This will pass this PR but it's weak. What do other systems do?
In XSD 1.1, differentiates between "canonical mapping" and "canonical representation". There is a canonical representation for
The is a canonical mapping is for the value. It does state the formats SPARQL systems are at liberty to provide Turtle-friendly forms (Jena does) or use what the programming language provides. What to do about it?
Example of 2 for |
|
Example for data that includes the outcome and a query that does detailed checking. The results are a table of "Pass" and "Fail" with expected and actual terms. Data, including outcomesPREFIX : <http://example/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
:n01_Zero_f :num "0"^^xsd:float ;
:expected "0"^^xsd:float .
:n02_Zero_d :num "0"^^xsd:double ;
:expected "0"^^xsd:double .
:n03_NegativeZero_f
:num "-0"^^xsd:float ;
:expected "-0"^^xsd:float .
:n04_NegativeZero_d
:num "-0"^^xsd:double ;
:expected "-0"^^xsd:double .
:n05_Positive_f
:num "0.1"^^xsd:float ;
:expected "0"^^xsd:float .
:n06_Positive_d
:num "0.1"^^xsd:double ;
:expected "0"^^xsd:double .
:n07_Negative_f
:num "-0.1"^^xsd:float ;
:expected "-0"^^xsd:float .
:n08_Negative_d
:num "-0.1"^^xsd:double ;
:expected "-0"^^xsd:double .
:n09_NaN_f
:num "NaN"^^xsd:float ;
:expected "NaN"^^xsd:float .
:n10_NaN_d
:num "NaN"^^xsd:double ;
:expected "NaN"^^xsd:double .
:n11_Inf_f
:num "INF"^^xsd:float ;
:expected "INF"^^xsd:float .
:n12_Inf_d
:num "INF"^^xsd:double ;
:expected "INF"^^xsd:double .
:n13_NegInf_f
:num "-INF"^^xsd:float ;
:expected "-INF"^^xsd:float .
:n14_NegInf_d
:num "-INF"^^xsd:double ;
:expected "-INF"^^xsd:double .
Query to process data with included outcomesPREFIX : <http://example/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?n ?outcome ?expected ?actual{
?n :num ?value ;
:expected ?expected .
BIND(round(?value) AS ?actual)
BIND(
IF(
## Same datatype
( datatype(?actual) = datatype(?expected) ) &&
## Same value or same term (for NaN)
( (?expected = ?actual) || (sameTerm(?expected, ?actual)) ) &&
## Same sign (for negative zero)
( ( ?expected >= 0 && ?actual >= 0 ) || ( ?expected < 0 && ?actual < 0 ) )
, "Pass"
, "Fail"
) AS ?outcome)
} ORDER BY ?nResults |
|
This is a great point. Thanks! I agree with you that option 2 is likely the best. I am going to update the tests. Fun aside: XSD has only a single lexical representation for INF, -INF and NaN so there is no issue for these cases. |
And yet |
Is it true IN SPARQL? In SPARQL 1.2 spec "NaN"^^xsd:double and "NaN"^^xsd:float are considered to represent the same value. If term1 and term2 are both "NaN" for either xsd:double or xsd:float, then return TRUE.But it's something specific to SPARQL 1.2 |
Yes - |
Yes.
For binary operations, float is promoted to double and "The result is the xs:double value that is the same as the original value".) This is treating INF/-INF/NaN as symbols used as point extension of the numbers to create a value space. (For point extensions, one has to define the meaning in all operations.) https://www.w3.org/TR/xpath-functions-31/#func-numeric-equal
which I read as The double and float "NaN"s could be different value points. I don't know of a way to observe the the design choice here. One hint is: https://www.w3.org/TR/xmlschema11-2/#double
https://www.w3.org/TR/xmlschema11-2/#dt-specialvalue
"distinguished from each other in the general case" would be "sameTerm" in RDF speak. float and double values spaces are different - the constants pick different points on the number line and finite numeric operations work on the number line (see promotions). Are the "special values" in the different values spaces different (fundamental) values? (fundamental values being the choice of point extensions.) Bottom line: I don't see text that is clearly definitive one way or the other. If you, I can move this to PR w3c/sparql-query#343. |
No description provided.