Difference between revisions of "Math Module"
Jump to navigation
Jump to search
| (18 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | The math [[Module Library|XQuery Module]] defines functions to perform mathematical operations, such as {{Code|pi}}, {{Code|asin}} and {{Code|acos}}. Most functions are specified in the [ | + | The math [[Module Library|XQuery Module]] defines functions to perform mathematical operations, such as {{Code|pi}}, {{Code|asin}} and {{Code|acos}}. Most functions are specified in the [https://www.w3.org/TR/xpath-functions-31/ Functions and Operators Specification] of the upcoming XQuery 3.0 Recommendation, and some additional ones have been added in this module. |
=Conventions= | =Conventions= | ||
| − | All functions in this module are assigned to the | + | All functions in this module are assigned to the <code><nowiki>http://www.w3.org/2005/xpath-functions/math</nowiki></code> namespace, which is statically bound to the {{Code|math}} prefix.<br/> |
=W3 Functions= | =W3 Functions= | ||
==math:pi== | ==math:pi== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:pi() as xs:double</pre> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| Line 23: | Line 23: | ||
==math:sqrt== | ==math:sqrt== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:sqrt( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the square root of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the {{Code|xs:double}} value of the mathematical square root of {{Code|$arg}}. | + | |Returns the square root of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the {{Code|xs:double}} value of the mathematical square root of {{Code|$arg}}. |
|} | |} | ||
==math:sin== | ==math:sin== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:sin( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the sine of the {{Code|$arg}}, expressed in radians.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the sine of {{Code|$arg}}, treated as an angle in radians. | + | |Returns the sine of the {{Code|$arg}}, expressed in radians.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the sine of {{Code|$arg}}, treated as an angle in radians. |
|} | |} | ||
==math:cos== | ==math:cos== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:cos( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the cosine of {{Code|$arg}}, expressed in radians.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the cosine of {{Code|$arg}}, treated as an angle in radians. | + | |Returns the cosine of {{Code|$arg}}, expressed in radians.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the cosine of {{Code|$arg}}, treated as an angle in radians. |
|} | |} | ||
==math:tan== | ==math:tan== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:tan( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the tangent of {{Code|$arg}}, expressed in radians.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the tangent of {{Code|$arg}}, treated as an angle in radians. | + | |Returns the tangent of {{Code|$arg}}, expressed in radians.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the tangent of {{Code|$arg}}, treated as an angle in radians. |
|} | |} | ||
==math:asin== | ==math:asin== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:asin( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the arc sine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc sine of {{Code|$arg}}, returned as an angle in radians in the range -π/2 to +π/2. | + | |Returns the arc sine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the arc sine of {{Code|$arg}}, returned as an angle in radians in the range -π/2 to +π/2. |
|} | |} | ||
==math:acos== | ==math:acos== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:acos( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the arc cosine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc cosine of {{Code|$arg}}, returned as an angle in radians in the range 0 to +π. | + | |Returns the arc cosine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the arc cosine of {{Code|$arg}}, returned as an angle in radians in the range 0 to +π. |
|} | |} | ||
==math:atan== | ==math:atan== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:atan( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the arc tangent of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc tangent of {{Code|$arg}}, returned as an angle in radians in the range -π/2 to +π/2. | + | |Returns the arc tangent of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the arc tangent of {{Code|$arg}}, returned as an angle in radians in the range -π/2 to +π/2. |
|} | |} | ||
==math:atan2== | ==math:atan2== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:atan2( |
| + | $arg1 as xs:double?, | ||
| + | $arg2 as xs:double | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the arc tangent of {{Code|$arg1}} divided by {{Code|$arg2}}, the result being in the range -π/2 to +π/2 radians.<br/>If {{Code|$arg1}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc tangent of {{Code|$arg1}} divided by {{Code|$arg2}}, returned as an angle in radians in the range -π to +π. | + | |Returns the arc tangent of {{Code|$arg1}} divided by {{Code|$arg2}}, the result being in the range -π/2 to +π/2 radians.<br/>If {{Code|$arg1}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the arc tangent of {{Code|$arg1}} divided by {{Code|$arg2}}, returned as an angle in radians in the range -π to +π. |
|} | |} | ||
==math:pow== | ==math:pow== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:pow( |
| + | $arg1 as xs:double?, | ||
| + | $arg2 as xs:double | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns {{Code|$arg1}} raised to the power of {{Code|$arg2}}.<br/>If {{Code|$arg1}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the {{Code|$arg1}} raised to the power of {{Code|$arg2}}. | + | |Returns {{Code|$arg1}} raised to the power of {{Code|$arg2}}.<br/>If {{Code|$arg1}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the {{Code|$arg1}} raised to the power of {{Code|$arg2}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 117: | Line 137: | ||
==math:exp== | ==math:exp== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:exp( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns <i>e</i> raised to the power of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the value of <i>e</i> raised to the power of {{Code|$arg}}. | + | |Returns <i>e</i> raised to the power of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the value of <i>e</i> raised to the power of {{Code|$arg}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 131: | Line 153: | ||
==math:log== | ==math:log== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:log( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the natural logarithm of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the natural logarithm (base <i>e</i>) of {{Code|$arg}}. | + | |Returns the natural logarithm of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the natural logarithm (base <i>e</i>) of {{Code|$arg}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 145: | Line 169: | ||
==math:log10== | ==math:log10== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:log10( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the base 10 logarithm of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the base 10 logarithm of {{Code|$arg}}. | + | |Returns the base 10 logarithm of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the base 10 logarithm of {{Code|$arg}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 161: | Line 187: | ||
==math:e== | ==math:e== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:e() as xs:double</pre> |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| Line 175: | Line 201: | ||
==math:sinh== | ==math:sinh== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:sinh( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the hyperbolic sine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic sine of {{Code|$arg}}. | + | |Returns the hyperbolic sine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the hyperbolic sine of {{Code|$arg}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 189: | Line 217: | ||
==math:cosh== | ==math:cosh== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:cosh( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the hyperbolic cosine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic cosine of {{Code|$arg}}. | + | |Returns the hyperbolic cosine of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the hyperbolic cosine of {{Code|$arg}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 203: | Line 233: | ||
==math:tanh== | ==math:tanh== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:tanh( |
| + | $arg as xs:double? | ||
| + | ) as xs:double?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Returns the hyperbolic tangent of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic tangent of {{Code|$arg}}. | + | |Returns the hyperbolic tangent of {{Code|$arg}}.<br/>If {{Code|$arg}} is the empty sequence, the empty sequence is returned.<br/>Otherwise the result is the hyperbolic tangent of {{Code|$arg}}. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
* {{Code|math:tanh(100)}} returns {{Code|1}}. | * {{Code|math:tanh(100)}} returns {{Code|1}}. | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|} | |} | ||
==math:crc32== | ==math:crc32== | ||
| − | {| | + | {| width='100%' |
|- | |- | ||
| − | | width=' | + | | width='120' | '''Signature''' |
| − | | | + | |<pre>math:crc32( |
| + | $string as xs:string? | ||
| + | ) as xs:hexBinary?</pre> | ||
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
| − | |Calculates the CRC32 check sum of the given | + | |Calculates the CRC32 check sum of the given {{Code|$string}}.<br/>If an empty sequence is supplied, the empty sequence is returned. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| Line 264: | Line 268: | ||
=Changelog= | =Changelog= | ||
| − | ; Version 7. | + | ; Version 9.1 |
| − | * Moved: math:random and math:uuid have been | + | * Updated: {{Function||math:crc32}} can be called with empty sequence. |
| + | |||
| + | ; Version 7.5 | ||
| + | * Moved: {{Code|math:random}} and {{Code|math:uuid}} have been moved to the [[Random Module]]. | ||
| + | |||
; Version 7.3 | ; Version 7.3 | ||
| − | * Added: | + | * Added: {{Function||math:crc32}} and {{Function||math:uuid}} have been adopted from the obsolete Utility Module. |
| − | |||
| − | |||
Latest revision as of 15:59, 9 March 2023
The math XQuery Module defines functions to perform mathematical operations, such as pi, asin and acos. Most functions are specified in the Functions and Operators Specification of the upcoming XQuery 3.0 Recommendation, and some additional ones have been added in this module.
Conventions[edit]
All functions in this module are assigned to the http://www.w3.org/2005/xpath-functions/math namespace, which is statically bound to the math prefix.
W3 Functions[edit]
math:pi[edit]
| Signature | math:pi() as xs:double |
| Summary | Returns the xs:double value of the mathematical constant π whose lexical representation is 3.141592653589793.
|
| Examples |
|
math:sqrt[edit]
| Signature | math:sqrt( $arg as xs:double? ) as xs:double? |
| Summary | Returns the square root of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the xs:double value of the mathematical square root of $arg.
|
math:sin[edit]
| Signature | math:sin( $arg as xs:double? ) as xs:double? |
| Summary | Returns the sine of the $arg, expressed in radians.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the sine of $arg, treated as an angle in radians.
|
math:cos[edit]
| Signature | math:cos( $arg as xs:double? ) as xs:double? |
| Summary | Returns the cosine of $arg, expressed in radians.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the cosine of $arg, treated as an angle in radians.
|
math:tan[edit]
| Signature | math:tan( $arg as xs:double? ) as xs:double? |
| Summary | Returns the tangent of $arg, expressed in radians.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the tangent of $arg, treated as an angle in radians.
|
math:asin[edit]
| Signature | math:asin( $arg as xs:double? ) as xs:double? |
| Summary | Returns the arc sine of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the arc sine of $arg, returned as an angle in radians in the range -π/2 to +π/2.
|
math:acos[edit]
| Signature | math:acos( $arg as xs:double? ) as xs:double? |
| Summary | Returns the arc cosine of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the arc cosine of $arg, returned as an angle in radians in the range 0 to +π.
|
math:atan[edit]
| Signature | math:atan( $arg as xs:double? ) as xs:double? |
| Summary | Returns the arc tangent of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the arc tangent of $arg, returned as an angle in radians in the range -π/2 to +π/2.
|
math:atan2[edit]
| Signature | math:atan2( $arg1 as xs:double?, $arg2 as xs:double ) as xs:double? |
| Summary | Returns the arc tangent of $arg1 divided by $arg2, the result being in the range -π/2 to +π/2 radians.If $arg1 is the empty sequence, the empty sequence is returned.Otherwise the result is the arc tangent of $arg1 divided by $arg2, returned as an angle in radians in the range -π to +π.
|
math:pow[edit]
| Signature | math:pow( $arg1 as xs:double?, $arg2 as xs:double ) as xs:double? |
| Summary | Returns $arg1 raised to the power of $arg2.If $arg1 is the empty sequence, the empty sequence is returned.Otherwise the result is the $arg1 raised to the power of $arg2.
|
| Examples |
|
math:exp[edit]
| Signature | math:exp( $arg as xs:double? ) as xs:double? |
| Summary | Returns e raised to the power of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the value of e raised to the power of $arg.
|
| Examples |
|
math:log[edit]
| Signature | math:log( $arg as xs:double? ) as xs:double? |
| Summary | Returns the natural logarithm of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the natural logarithm (base e) of $arg.
|
| Examples |
|
math:log10[edit]
| Signature | math:log10( $arg as xs:double? ) as xs:double? |
| Summary | Returns the base 10 logarithm of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the base 10 logarithm of $arg.
|
| Examples |
|
Additional Functions[edit]
math:e[edit]
| Signature | math:e() as xs:double |
| Summary | Returns the xs:double value of the mathematical constant e whose lexical representation is 2.718281828459045.
|
| Examples |
|
math:sinh[edit]
| Signature | math:sinh( $arg as xs:double? ) as xs:double? |
| Summary | Returns the hyperbolic sine of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the hyperbolic sine of $arg.
|
| Examples |
|
math:cosh[edit]
| Signature | math:cosh( $arg as xs:double? ) as xs:double? |
| Summary | Returns the hyperbolic cosine of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the hyperbolic cosine of $arg.
|
| Examples |
|
math:tanh[edit]
| Signature | math:tanh( $arg as xs:double? ) as xs:double? |
| Summary | Returns the hyperbolic tangent of $arg.If $arg is the empty sequence, the empty sequence is returned.Otherwise the result is the hyperbolic tangent of $arg.
|
| Examples |
|
math:crc32[edit]
| Signature | math:crc32( $string as xs:string? ) as xs:hexBinary? |
| Summary | Calculates the CRC32 check sum of the given $string.If an empty sequence is supplied, the empty sequence is returned. |
| Examples |
|
Changelog[edit]
- Version 9.1
- Updated:
math:crc32can be called with empty sequence.
- Version 7.5
- Moved:
math:randomandmath:uuidhave been moved to the Random Module.
- Version 7.3
- Added:
math:crc32andmath:uuidhave been adopted from the obsolete Utility Module.