<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29408</bug_id>
          
          <creation_ts>2016-01-30 10:36:38 +0000</creation_ts>
          <short_desc>[QT3] Precision in extvardeclwithouttype-18</short_desc>
          <delta_ts>2016-04-14 18:59:01 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XQuery 3 &amp; XPath 3 Test Suite</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Benito van der Zander">benito</reporter>
          <assigned_to name="O&apos;Neil Delpratt">oneil</assigned_to>
          <cc>abel.braaksma</cc>
    
    <cc>andrew_coleman</cc>
    
    <cc>mike</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>124762</commentid>
    <comment_count>0</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-01-30 10:36:38 +0000</bug_when>
    <thetext>The test uses as supposingly simple input avg((1,2,4)) and expects 2.333333333333333333 or 2.333333333333. 
But it is evaluated as 7 div 3, which becomes an xs:decimal which has implementation-defined precision (For xs:decimal values the number of digits of precision returned by the numeric operators is ·implementation-defined·.).
My implementation returns 2.33333333333333333</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125599</commentid>
    <comment_count>1</comment_count>
    <who name="O&apos;Neil Delpratt">oneil</who>
    <bug_when>2016-03-22 15:35:37 +0000</bug_when>
    <thetext>The WG discussed this issue at today&apos;s telcon. The resolution is to use the assert-eq which allows us compare the actual result with &apos;7 div 3&apos;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125600</commentid>
    <comment_count>2</comment_count>
    <who name="O&apos;Neil Delpratt">oneil</who>
    <bug_when>2016-03-22 15:54:35 +0000</bug_when>
    <thetext>The resolution of &apos;7 div 3&apos; adds the potential risk of allowing any answer. What would be better is to give a range of something between 2.332 and 2.334, or similar. Maybe there is a minimum preision that we can use here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125601</commentid>
    <comment_count>3</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-03-22 15:58:21 +0000</bug_when>
    <thetext>Or a regular expression

2\.3+</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125702</commentid>
    <comment_count>4</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-04-03 23:50:25 +0000</bug_when>
    <thetext>I would like to push back on the proposed solutions in comment#2 and comment#3.

fn:avg((1,2,4)) is fn:sum((1,2,4)) div 3, which is xs:integer(7) div xs:integer(3) resulting in xs:decimal with value of 7/3.

The spec mandates that minimally conforming processors support at least 18 total digits (XSD 1.0) or 16 total digits (XSD 1.1, see also Bug 29552) . That means that:

2.33333333333333333 (Benito&apos;s processor, is correct: 18 digits)
2.333333333333333 (XSD 1.1 minimum, is correct: 16 digits)
2.333333333333 (alternative in current test is incorrect: 13 digits)
2.333333333333333333 (alternative in current test is allowed, but not required: 19 digits)

The solution in comment#2 allows wrong answers regardless of the precision, and the solution in comment#3 allows too little precision. I suggest something like any of the following three alternatives:

exact: 2.33333333333333333
exact: 2.333333333333333
regex: 2.333333333333333333+

Since rounding is not an issue here, any precision will always end with a sequence of &quot;3&quot;, so this will work as well and catches all mandatory and optional precisions (preventing an implementation to allow, for instance, to have 2.333300 or 2.33334 as valid answer):

regex: 2.333333333333333(33+)?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125703</commentid>
    <comment_count>5</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-04-03 23:51:22 +0000</bug_when>
    <thetext>&gt; regex: 2.333333333333333(33+)?
that should probably be ^2.333333333333333(33+)?$</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125705</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-04-04 08:37:02 +0000</bug_when>
    <thetext>F+O says in section 4.2:

For xs:decimal values the number of digits of precision returned by the numeric operators is ·implementation-defined·.

This is probably far more liberal than we really intended: for example it allows 1.01 + 1.04 to return 2. However, it doesn&apos;t say that the result of division must have any particular minimum precision, and I don&apos;t think we should read it as if it did.

As a further complication, there is no requirement to implement avg((1,2,4)) as sum((1,2,4)) div count((1,2,4)): we say that &quot;the implementation may use an otherwise equivalent algorithm that avoids arithmetic overflow&quot;. Avoiding overflow may well involve loss of precision, and the loss of precision can be justified by the fact that the precision of &quot;div&quot; is implementation defined. So a final result like 2.33333333334 is not at all out of the question.

Pragmatically, the spec is loosely worded in this area and it therefore makes sense for the corresponding tests to have loosely-defined pass criteria.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125724</commentid>
    <comment_count>7</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-04-05 15:08:20 +0000</bug_when>
    <thetext>&gt; may use an otherwise equivalent algorithm that avoids arithmetic overflow
I would understand &quot;equivalent&quot; as not allowing a different outcome...

&gt; For xs:decimal values the number of digits of precision returned by the 
&gt; numeric operators is ·implementation-defined·.
I understood that as the implementation-defined limit we have on xs:decimal anyway, with a minimum of 18 digits. I think (but not sure) that in IEEE-754 there&apos;s a section on decimals that requires additional digits if necessary to prevent precision-issues, but I don&apos;t think XPath leans on IEEE-754 for decimal arithmetic (only used for double/float).

If what you are say is the de facto rule, then I think there are many tests that should be more lenient in what answers they expect. I remember fixing quite a few on my end to get the proper amount of digits in the result to fit the tests....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125726</commentid>
    <comment_count>8</comment_count>
    <who name="Benito van der Zander">benito</who>
    <bug_when>2016-04-05 15:49:05 +0000</bug_when>
    <thetext>&gt;I remember fixing quite a few on my end to get the proper amount of digits in the result to fit the tests....

I, for one, even had to write an entire arbitrary precision arithmetic library for that.

That some other xs:float test wanted 2.33333... and did not accept 2.33...34 helped to find a bug there</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125863</commentid>
    <comment_count>9</comment_count>
    <who name="Andrew Coleman">andrew_coleman</who>
    <bug_when>2016-04-14 18:59:01 +0000</bug_when>
    <thetext>At the meeting on 2016-04-12, the WG decided:
Add text along these lines to the F&amp;O specification:

   &quot;implementation_defined&quot; for results of calculations with
   xs:decimal or derived types *SHOULD* be at least the minimal
   requirement for the number of digits to be supported for xs:decimal

Tests will reflect the above semantics.

Action A-639-06 was raised to track this change</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>