<?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>29430</bug_id>
          
          <creation_ts>2016-02-07 18:39:42 +0000</creation_ts>
          <short_desc>[FO31] Resulting type of numeric functions</short_desc>
          <delta_ts>2016-03-03 10:13:14 +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>Functions and Operators 3.1</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>WORKSFORME</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="Abel Braaksma">abel.braaksma</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <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>124893</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-02-07 18:39:42 +0000</bug_when>
    <thetext>This bug report originated from the discussion in bug 29420, a QT3 test bug.

The question I would like to raise is what type is expected to be returned:

   fn:sum((xs:byte(1), xs:byte(2))
   fn:sum((xs:unsignedShort(12), xs:unsignedShort(24))
   fn:sum((xs:nonNegativeInteger(42), xs:nonNegativeInteger(42))

My take is that, since fn:sum is defined in terms of op:numeric-plus, section 4.2 applies and they should all return xs:integer. That does not prevent them from return xs:byte, xs:unsignedShort, xs:nonNegativeInteger, but if an implementation does not return those types, it should return xs:integer (and not an xs:decimal that is itself not also an xs:integer).

Michael Kay argues in bug 29240, comment#5 that the rules in section 4.2 do not apply for fn:sum, but I think they do.

Considering the confusion this caused, does it makes sense, and is there room, for writing this up somehow? I.e., change this:

&lt;quote&gt;
The sum of a sequence of integers will therefore be an integer, while the sum of a numeric sequence that includes at least one xs:double will be an xs:double.
&lt;/quote&gt;

into something like this (in particular add &quot;of more than one&quot;):

&lt;quote&gt;
The sum of a sequence of more than one integers will therefore be an integer, while the sum of a numeric sequence that includes at least one xs:double will be an xs:double. The sum of a singleton will always retain its type, while the sum of an empty sequence takes the type of the second argument, or xs:integer is absent.
&lt;/quote&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125000</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-02-11 22:18:00 +0000</bug_when>
    <thetext>There are missing parentheses in your examples but I assume the intended expressions are

   fn:sum((xs:byte(1), xs:byte(2)))
   fn:sum((xs:unsignedShort(12), xs:unsignedShort(24)))
   fn:sum((xs:nonNegativeInteger(42), xs:nonNegativeInteger(42)))

that is, in each case we are concerned with sum#1 rather than sum#2.

&gt;My take is that, since fn:sum is defined in terms of op:numeric-plus, section 4.2 applies and they should all return xs:integer. That does not prevent them from return xs:byte, xs:unsignedShort, xs:nonNegativeInteger, 

I agree with that.

&gt;Michael Kay argues in bug 29240, comment#5 that the rules in section 4.2 do not apply for fn:sum, but I think they do.

I was arguing that the rules in section 4.2 do not apply to fn:sum() when the first argument to fn:sum is a singleton, because in that case op:numeric-plus is not invoked. The rules for fn:sum say that when the first argument is a singleton, it is returned unchanged.

&gt;Considering the confusion this caused

Personally I think fn:sum is quite wordy enough already, and that saying the same thing in three different ways does not always add clarity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125185</commentid>
    <comment_count>2</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-02-20 17:50:42 +0000</bug_when>
    <thetext>It looks like part of the confusion came from me mixing the sum#1 and sum#2 and/or the sequence-of-one vs the sequence-of-more-than-one as first argument.

I think the current spec says this:

sum#1, if empty seq return xs:integer(0)
sum#1, if seq-of-one return $arg1 unchanged (keep type)
sum#1, if seq-gt-than-one convert result to xs:integer/xs:double etc
sum#2, if empty seq return $arg2 unchanged (keep type)
sum#2, with non-empty $arg1 same as sum#1.

If this is how it is supposed to work then I think that my argument is void. I thought we both had a different reading of the spec (and add to that some additional confusion on my end), but this appears not the case.

If that&apos;s indeed the case, let&apos;s close with no action.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>125332</commentid>
    <comment_count>3</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-03-03 10:13:06 +0000</bug_when>
    <thetext>Following decision from WG meeting #634, this bug can now be closed with no action.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>