Changes

Jump to navigation Jump to search
316 bytes added ,  14:39, 16 April 2019
no edit summary
The math [[Module Library|XQuery Module]] defines functions to perform mathematical operations, such as <code>{{Code|pi</code>}}, <code>{{Code|asin</code> }} and <code>{{Code|acos</code>}}. Most functions are specified in the [http://www.w3.org/TR/xpath-functions-30/ Functions and Operators Specification] of the upcoming XQuery 3.0 Recommendation, and some additional ones have been added in this module.
=Conventions=
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>{{Code|math</code> }} prefix.<br/>
=W3 Functions=
==math:pi==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:pi</b>() as ||xs:double</code>}}
|-
| '''Summary'''
|Returns the <code>{{Code|xs:double</code> }} value of the mathematical constant π whose lexical representation is 3.141592653589793.
|-
| '''Examples'''
|
* <code>{{Code|2*math:pi()</code> }} returns <code>{{Code|6.283185307179586e0</code>}}.* <code>{{Code|60 * (math:pi() div 180)</code> }} converts an angle of 60 degrees to radians.|} ==math:e=={||-| width='90' | '''Signatures'''|<code><b>math:e</b>() as xs:double</code>|-| '''Summary'''|Returns the <code>xs:double</code> value of the mathematical constant <i>e</i> whose lexical representation is 2.718281828459045.|-| '''Examples'''|* <code>5*math:e()</code> returns <code>13.591409142295225</code>.
|}
==math:sqrt==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:sqrt</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the square root of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the <code>{{Code|xs:double</code> }} value of the mathematical square root of <code>{{Code|$arg</code>}}.
|}
==math:sin==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:sin</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the sine of the <code>{{Code|$arg</code>}}, expressed in radians.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the sine of <code>{{Code|$arg</code>}}, treated as an angle in radians.
|}
==math:cos==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:cos</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the cosine of <code>{{Code|$arg</code>}}, expressed in radians.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the cosine of <code>{{Code|$arg</code>}}, treated as an angle in radians.
|}
==math:tan==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:tan</b>(|$ arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the tangent of <code>{{Code|$arg</code>}}, expressed in radians.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the tangent of <code>{{Code|$arg</code>}}, treated as an angle in radians.
|}
==math:asin==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:asin</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the arc sine of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc sine of <code>{{Code|$arg</code>}}, returned as an angle in radians in the range -π/2 to +π/2.
|}
==math:acos==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:acos</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the arc cosine of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc cosine of <code>{{Code|$arg</code>}}, returned as an angle in radians in the range 0 to +π.
|}
==math:atan==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:atan</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the arc tangent of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc tangent of <code>{{Code|$arg</code>}}, returned as an angle in radians in the range -π/2 to +π/2.
|}
==math:atan2==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:atan2</b>(|$arg1 as xs:double?, $arg2 as xs:double) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the arc tangent of <code>{{Code|$arg1</code> }} divided by <code>{{Code|$arg2</code>}}, the result being in the range -π/2 to +π/2 radians.<br/>If <code>{{Code|$arg1</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc tangent of <code>{{Code|$arg1</code> }} divided by <code>{{Code|$arg2</code>}}, returned as an angle in radians in the range -π to +π.
|}
==math:pow==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:pow</b>(|$arg1 as xs:double?, $arg2 as xs:double) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns <code>{{Code|$arg1</code> }} raised to the power of <code>{{Code|$arg2</code>}}.<br/>If <code>{{Code|$arg1</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the <code>{{Code|$arg1</code> }} raised to the power of <code>{{Code|$arg2</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:pow(2, 3)</code> }} returns <code>{{Code|8</code>}}.
|}
==math:exp==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:exp</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns <i>e</i> raised to the power of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} 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>{{Code|$arg</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:exp(1)</code> }} returns <i>e</i>.
|}
==math:log==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:log</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the natural logarithm of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the natural logarithm (base <i>e</i>) of <code>{{Code|$arg</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:log(math:e())</code> }} returns <code>{{Code|1</code>}}.
|}
==math:log10==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:log10</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the base 10 logarithm of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the base 10 logarithm of <code>{{Code|$arg</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:log(100)</code> }} returns <code>{{Code|2</code>}}.
|}
=Additional Functions= ==math:randome=={|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:random</b>() as e||xs:double?</code>}}
|-
| '''Summary'''
|Returns a random <code>the {{Code|xs:double</code> }} value between of the mathematical constant <codei>0.0e</codei> and <code>1whose lexical representation is 2.718281828459045.|-| '''Examples'''|* {{Code|5*math:e()}} returns {{Code|13.0</code>591409142295225}}.
|}
==math:sinh==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:sinh</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the hyperbolic sine of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic sine of <code>{{Code|$arg</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:sinh(0)</code> }} returns <code>{{Code|0</code>}}.
|}
==math:cosh==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:cosh</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the hyperbolic cosine of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic cosine of <code>{{Code|$arg</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:cosh(0)</code> }} returns <code>{{Code|1</code>}}.
|}
==math:tanh==
{|width='100%'
|-
| width='90120' | '''Signatures'''|<code><b>{{Func|math:tanh</b>(|$arg as xs:double?) as |xs:double?</code>}}
|-
| '''Summary'''
|Returns the hyperbolic tangent of <code>{{Code|$arg</code>}}.<br/>If <code>{{Code|$arg</code> }} is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic tangent of <code>{{Code|$arg</code>}}.
|-
| '''Examples'''
|
* <code>{{Code|math:tanh(100)</code> }} returns <code>{{Code|1</code>}}.
|}
==math:crc32== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|math:crc32|$string as xs:string?|xs:hexBinary?}}<br />|-| '''Summary'''|Calculates the CRC32 check sum of the given {{Code|$string}}.<br/>If an empty sequence is supplied, the empty sequence is returned.|-| '''Examples'''|* {{Code|math:crc32("")}} returns {{Code|'00000000'}}.* {{Code|math:crc32("BaseX")}} returns {{Code|'4C06FC7F'}}.|} =Changelog= ; Version 9.1* Updated: [[#math:crc32|math:crc32]] can be called with empty sequence. ; Version 7.5* Moved: [[Random Module#random:integer|math:random]] and [[Random Module#random:uuid|math:uuid]] have been moved to [[CategoryRandom Module]]. ; Version 7.3* Added: [[#math:crc32|math:crc32]] and [[Random Module#random:uuid|math:XQueryuuid]]have been adopted from the obsolete Utility Module.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu