Bug 4621 - [FO] rounding for duration *|div number
: [FO] rounding for duration *|div number
Status: CLOSED FIXED
Product: XPath / XQuery / XSLT
Functions and Operators 1.0
: Recommendation
: PC Windows XP
: P2 normal
: ---
Assigned To: Ashok Malhotra
: Mailing list for public feedback on specs from XSL and XML Query WGs
:
:
:
:
:
  Show dependency treegraph
 
Reported: 2007-06-10 23:38 UTC by Michael Kay
Modified: 2007-11-16 09:18 UTC (History)
0 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Kay 2007-06-10 23:38:54 UTC
This arises from bug 713 (member-only) against the XSLT test suite.

What is the correct result of xs:yearMonthDuration('-P1M')*0.5, or
xs:yearMonthDuration('-P1M') div 2? 

The spec says (10.6.3, 10.6.4) "The result is rounded to the nearest month. For
a value v, 0 <= v < 0.5 rounds to 0; 0.5 <= v < 1.0 rounds to 1." It's not
clear from that which way the rounding works for negative numbers.

My proposal would be to follow the rules of the round() function, so -0.5
rounds to 0. Specifically, the result should be the yearMonthDuration whose
length in months is equal to round() applied to result of multiplying/dividing
the length in months of $arg1 by the value of $arg2.
Comment 1 Ashok Malhotra 2007-06-11 13:33:06 UTC
Makes sense.  In fact, we should say that the result is computed using
fn:round().
Comment 2 Michael Kay 2007-06-12 20:31:39 UTC
Proposed change:

1. Change the summary of the two functions from

Summary: Returns the result of [multiplying|dividing] the value of $arg1 by
$arg2. The result is rounded to the nearest month. For a value v, 0 <= v < 0.5
rounds to 0; 0.5 <= v < 1.0 rounds to 1.

to

Summary: Returns the result of [multiplying|dividing] the value of $arg1 by
$arg2. The result is rounded to the nearest month.

2. Add immediately after the summary of each function, the paragraph:

The result is the xs:yearMonthDuration whose length in months is equal to the
result of applying the fn:round function to the value obtained by
[multiplying|dividing] the length in months of $arg1 by the value of $arg2.
Comment 3 Michael Kay 2007-06-27 14:58:16 UTC
This wording was accepted by the WGs on 27 June 2007
Comment 4 Michael Kay 2007-07-31 20:20:09 UTC
Erratum FO-E12 has been drafted.


  翻译: