From 1c00c95646ff05f6bad7802f5c98cad3258012ea Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Wed, 1 Jan 2025 16:49:22 +0000 Subject: [PATCH 1/3] new divide-decimals function --- .../src/function-catalog.xml | 91 +++++++++++++++++++ .../src/xpath-functions.xml | 3 + 2 files changed, 94 insertions(+) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 3b44fb539..38d61b037 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -2359,6 +2359,97 @@ compare($N * $arg2, 0) eq compare($arg1, 0). + + + + + + + + + + + + deterministic + context-independent + focus-independent + + +

Divides one xs:decimal by another to a defined precision, returning + both the quotient and the remainder.

+
+ +

The function returns a record with two fields:

+ + +

quotient is the xs:decimal value + furthest from zero such that:

+ +

quotient is an exact multiple of ten to the power + of minus $precision, and

+

the absolute value of quotient + multipled by $divisor is less than or equal to the absolute + value of $value.

+
+
+ +

remainder is the exact result of subtracting quotient + multiplied by $divisor from $value.

+
+
+ +

If $precision exceeds the maximum precision for xs:decimal + values supported by the implementation, then the maximum available precision is + used in its place.

+ +
+ + + + + divide-decimals(120.6, 60.3, 4) + { "quotient": 2, "remainder": 0 } + + + divide-decimals(10, 3) + { "quotient": 3, "remainder": 1 } + + + divide-decimals(10, -3) + { "quotient": -3, "remainder": 1 } + + + divide-decimals(-10, 3) + { "quotient": -3, "remainder": -1 } + + + divide-decimals(-10, -3) + { "quotient": 3, "remainder": -1 } + + + divide-decimals(10, 3, 6) + { "quotient": 3.333333, "remainder": 0.000001 } + + + divide-decimals(100, 30) + { "quotient": 3, "remainder": 10 } + + + divide-decimals(150_862, 7, -3) + { "quotient": 21_000, "remainder": 3_862 } + + + + + + +

New in 4.0.

+
+
+
+ + + diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index 26dd5fe92..12e3e485a 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -1951,6 +1951,9 @@ This differs from , which defines + + + From ff4bab3db90375b90b628898fe3921f8dea8bccf Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Wed, 1 Jan 2025 21:59:38 +0000 Subject: [PATCH 2/3] Tighten the spec --- .../xpath-functions-40/src/function-catalog.xml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 38d61b037..17f1ac681 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -2386,10 +2386,12 @@ compare($N * $arg2, 0) eq compare($arg1, 0). furthest from zero such that:

quotient is an exact multiple of ten to the power - of minus $precision, and

+ of minus $precision;

the absolute value of quotient multipled by $divisor is less than or equal to the absolute - value of $value.

+ value of $value;

+

the sign of quotient is the same as the sign + of op:numeric-divide($value, $divisor).

@@ -2403,6 +2405,10 @@ compare($N * $arg2, 0) eq compare($arg1, 0). used in its place.

+ +

A dynamic error is raised + if $divisor is zero.

+
@@ -2437,8 +2443,7 @@ compare($N * $arg2, 0) eq compare($arg1, 0). divide-decimals(150_862, 7, -3) { "quotient": 21_000, "remainder": 3_862 } - - + From c1caca68ea1592271404eead1a4c36f0a223b634 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Wed, 1 Jan 2025 22:05:16 +0000 Subject: [PATCH 3/3] Fix markup error --- specifications/xpath-functions-40/src/function-catalog.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 17f1ac681..42cf6b887 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -2408,7 +2408,7 @@ compare($N * $arg2, 0) eq compare($arg1, 0).

A dynamic error is raised if $divisor is zero.

-