Difference between revisions of "Math Module"

From BaseX Documentation
Jump to navigation Jump to search
 
(53 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<p>The math module defines extension functions to perform mathematical operations, such as <code>pi</code>, <code>asin</code> and <code>acos</code>. All functions are preceded by the <code>math:</code> prefix. Some of the functions have also been 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.
[http://www.w3.org/TR/xpath-functions-11/ Functions and Operators Specification] of the upcoming XQuery 1.1 Recommendation.</p>
+
 
+
=Conventions=
<h2>math:pi</h2>  
+
 
<table>  
+
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/>
  <tr>  
+
 
    <td width="90">  
+
=W3 Functions=
      <b>Signatures</b>  
+
 
    </td>
+
==math:pi==
    <td>
+
{| width='100%'
      <code>
+
|-
        <b>math:pi</b>() as xs:double</code>
+
| width='120' | '''Signature'''
      <br />
+
|<pre>math:pi() as xs:double</pre>
    </td>  
+
|-
  </tr>  
+
| '''Summary'''
  <tr>
+
|Returns the {{Code|xs:double}} value of the mathematical constant π whose lexical representation is 3.141592653589793.
    <td>
+
|-
      <b>Summary</b>
+
| '''Examples'''
    </td>
+
|
    <td>Returns the value of the mathematical constant π.</td>
+
* {{Code|2*math:pi()}} returns {{Code|6.283185307179586e0}}.
  </tr>
+
* {{Code|60 * (math:pi() div 180)}} converts an angle of 60 degrees to radians.
  <tr>
+
|}
    <td>
+
 
      <b>Rules</b>
+
==math:sqrt==
    </td>
+
{| width='100%'
    <td>This function returns the <code>xs:double</code> value whose lexical representation is 3.141592653589793.<br />
+
|-
    </td>
+
| width='120' | '''Signature'''
  </tr>
+
|<pre>math:sqrt(
  <tr>
+
  $arg  as xs:double?
    <td>
+
) as xs:double?</pre>
      <b>Examples</b>  
+
|-
    </td>
+
| '''Summary'''
    <td>The expression <code>2*math:pi()</code> returns <code>6.283185307179586e0</code>.<br />The expression <code>60 * (math:pi() div 180)</code> converts an angle of 60 degrees to radians.<br />
+
|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}}.
    </td>
+
|}
  </tr>
+
 
</table>
+
==math:sin==
+
{| width='100%'
<h2>math:e</h2>
+
|-
<table>
+
| width='120' | '''Signature'''
  <tr>
+
|<pre>math:sin(
    <td width="90">
+
  $arg  as xs:double?
      <b>Signatures</b>
+
) as xs:double?</pre>
    </td>
+
|-
    <td>
+
| '''Summary'''
      <code>
+
|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.
        <b>math:e</b>() as xs:double</code>  
+
|}
      <br />  
+
 
    </td>
+
==math:cos==
  </tr>  
+
{| width='100%'
  <tr>
+
|-
    <td>
+
| width='120' | '''Signature'''
      <b>Summary</b>
+
|<pre>math:cos(
    </td>
+
   $arg  as xs:double?
    <td>Returns the value of the mathematical constant <i>e</i>.</td>  
+
) as xs:double?</pre>
   </tr>  
+
|-
  <tr>
+
| '''Summary'''
    <td>
+
|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.
      <b>Rules</b>  
+
|}
    </td>  
+
 
    <td>This function returns the <code>xs:double</code> value whose lexical representation is 2.718281828459045.<br />
+
==math:tan==
    </td>
+
{| width='100%'
  </tr>
+
|-
  <tr>
+
| width='120' | '''Signature'''
    <td>
+
|<pre>math:tan(
      <b>Examples</b>  
+
  $arg  as xs:double?
    </td>
+
) as xs:double?</pre>
    <td>The expression <code>5*math:e()</code> returns <code>13.591409142295225</code>.<br />  
+
|-
    </td>
+
| '''Summary'''
  </tr>
+
|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.
</table>
+
|}
+
 
<h2>math:sqrt</h2>
+
==math:asin==
<table>
+
{| width='100%'
  <tr>
+
|-
    <td width="90">
+
| width='120' | '''Signature'''
      <b>Signatures</b>  
+
|<pre>math:asin(
    </td>
+
  $arg  as xs:double?
    <td>
+
) as xs:double?</pre>
      <code>
+
|-
        <b>math:sqrt</b>($arg as xs:double?) as xs:double?</code>  
+
| '''Summary'''
      <br />  
+
|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.
    </td>  
+
|}
  </tr>
+
 
  <tr>
+
==math:acos==
    <td>
+
{| width='100%'
      <b>Summary</b>
+
|-
    </td>
+
| width='120' | '''Signature'''
    <td>Returns the square root of the argument.</td>
+
|<pre>math:acos(
  </tr>
+
  $arg as xs:double?
  <tr>
+
) as xs:double?</pre>
    <td>
+
|-
      <b>Rules</b>
+
| '''Summary'''
    </td>  
+
|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 +π.
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the <code>xs:double</code> value of the mathematical square root of <code>$arg</code>.<br />
+
|}
    </td>
+
 
  </tr>
+
==math:atan==
</table>
+
{| width='100%'
+
|-
<h2>math:sin</h2>
+
| width='120' | '''Signature'''
<table>
+
|<pre>math:atan(
  <tr>
+
  $arg as xs:double?
    <td width="90">
+
) as xs:double?</pre>
      <b>Signatures</b>  
+
|-
    </td>
+
| '''Summary'''
    <td>
+
|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.
      <code>
+
|}
        <b>math:sin</b>($arg as xs:double?) as xs:double?</code>  
+
 
      <br />
+
==math:atan2==
    </td>
+
{| width='100%'
  </tr>  
+
|-
  <tr>
+
| width='120' | '''Signature'''
    <td>
+
|<pre>math:atan2(
      <b>Summary</b>  
+
  $arg1  as xs:double?,
    </td>
+
  $arg2  as xs:double
    <td>Returns the sine of the argument, expressed in radians.</td>
+
) as xs:double?</pre>
  </tr>
+
|-
  <tr>
+
| '''Summary'''
    <td>
+
|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 +π.
      <b>Rules</b>
+
|}
    </td>
+
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the sine of <code>$arg</code>, treated as an angle in radians.<br />
+
==math:pow==
    </td>
+
{| width='100%'
  </tr>
+
|-
</table>
+
| width='120' | '''Signature'''
+
|<pre>math:pow(
<h2>math:cos</h2>
+
  $arg1  as xs:double?,
<table>
+
  $arg2  as xs:double
  <tr>
+
) as xs:double?</pre>
    <td width="90">
+
|-
      <b>Signatures</b>
+
| '''Summary'''
    </td>
+
|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}}.
    <td>
+
|-
      <code>
+
| '''Examples'''
        <b>math:cos</b>($arg as xs:double?) as xs:double?</code>  
+
|
      <br />
+
* {{Code|math:pow(2, 3)}} returns {{Code|8}}.
    </td>
+
|}
  </tr>  
+
 
  <tr>
+
==math:exp==
    <td>
+
{| width='100%'
      <b>Summary</b>  
+
|-
    </td>
+
| width='120' | '''Signature'''
    <td>Returns the cosine of the argument, expressed in radians.</td>
+
|<pre>math:exp(
  </tr>
+
  $arg as xs:double?
  <tr>
+
) as xs:double?</pre>
    <td>
+
|-
      <b>Rules</b>
+
| '''Summary'''
    </td>
+
|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}}.
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the cosine of <code>$arg</code>, treated as an angle in radians.<br />  
+
|-
    </td>
+
| '''Examples'''
  </tr>  
+
|
</table>  
+
* {{Code|math:exp(1)}} returns <i>e</i>.
+
|}
<h2>math:tan</h2>  
+
 
<table>
+
==math:log==
  <tr>  
+
{| width='100%'
    <td width="90">  
+
|-
      <b>Signatures</b>
+
| width='120' | '''Signature'''
    </td>  
+
|<pre>math:log(
    <td>
+
   $arg  as xs:double?
      <code>
+
) as xs:double?</pre>
        <b>math:tan</b>($ as xs:double?) as xs:double?</code>
+
|-
      <br />
+
| '''Summary'''
    </td>
+
|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}}.
  </tr>  
+
|-
   <tr>
+
| '''Examples'''
    <td>  
+
|
      <b>Summary</b>
+
* {{Code|math:log(math:e())}} returns {{Code|1}}.
    </td>
+
|}
    <td>Returns the tangent of the argument, expressed in radians.</td>  
+
 
  </tr>  
+
==math:log10==
  <tr>  
+
{| width='100%'
    <td>
+
|-
      <b>Rules</b>
+
| width='120' | '''Signature'''
    </td>
+
|<pre>math:log10(
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the tangent of <code>$arg</code>, treated as an angle in radians.<br />
+
  $arg as xs:double?
    </td>  
+
) as xs:double?</pre>
  </tr>
+
|-
</table>
+
| '''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}}.
<h2>math:asin</h2>  
+
|-
<table>
+
| '''Examples'''
  <tr>
+
|
    <td width="90">
+
* {{Code|math:log(100)}} returns {{Code|2}}.
      <b>Signatures</b>
+
|}
    </td>
+
 
    <td>
+
=Additional Functions=
      <code>
+
 
        <b>math:asin</b>($arg as xs:double?) as xs:double?</code>  
+
==math:e==
      <br />
+
{| width='100%'
    </td>
+
|-
  </tr>
+
| width='120' | '''Signature'''
  <tr>  
+
|<pre>math:e() as xs:double</pre>
    <td>
+
|-
      <b>Summary</b>  
+
| '''Summary'''
    </td>
+
|Returns the {{Code|xs:double}} value of the mathematical constant <i>e</i> whose lexical representation is 2.718281828459045.
    <td>Returns the arc sine of the argument.</td>
+
|-
  </tr>
+
| '''Examples'''
  <tr>
+
|
    <td>
+
* {{Code|5*math:e()}} returns {{Code|13.591409142295225}}.
      <b>Rules</b>
+
|}
    </td>
+
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the arc sine of <code>$arg</code>, returned as an angle in radians in the range -π/2 to +π/2.<br />
+
==math:sinh==
    </td>
+
{| width='100%'
  </tr>
+
|-
</table>
+
| width='120' | '''Signature'''
+
|<pre>math:sinh(
<h2>math:acos</h2>
+
  $arg as xs:double?
<table>
+
) as xs:double?</pre>
  <tr>
+
|-
    <td width="90">
+
| '''Summary'''
      <b>Signatures</b>
+
|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}}.
    </td>
+
|-
    <td>
+
| '''Examples'''
      <code>
+
|
        <b>math:acos</b>($arg as xs:double?) as xs:double?</code>  
+
* {{Code|math:sinh(0)}} returns {{Code|0}}.
      <br />
+
|}
    </td>
+
 
  </tr>
+
==math:cosh==
  <tr>
+
{| width='100%'
    <td>
+
|-
      <b>Summary</b>
+
| width='120' | '''Signature'''
    </td>
+
|<pre>math:cosh(
    <td>Returns the arc cosine of the argument.</td>
+
  $arg as xs:double?
  </tr>
+
) as xs:double?</pre>
  <tr>
+
|-
    <td>
+
| '''Summary'''
      <b>Rules</b>
+
|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}}.
    </td>
+
|-
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the arc cosine of <code>$arg</code>, returned as an angle in radians in the range 0 to +π.<br />
+
| '''Examples'''
    </td>
+
|
  </tr>
+
* {{Code|math:cosh(0)}} returns {{Code|1}}.
</table>
+
|}
+
 
<h2>math:atan</h2>
+
==math:tanh==
<table>
+
{| width='100%'
  <tr>
+
|-
    <td width="90">
+
| width='120' | '''Signature'''
      <b>Signatures</b>
+
|<pre>math:tanh(
    </td>
+
  $arg as xs:double?
    <td>
+
) as xs:double?</pre>
      <code>
+
|-
        <b>math:atan</b>($arg as xs:double?) as xs:double?</code>  
+
| '''Summary'''
      <br />  
+
|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}}.
    </td>  
+
|-
  </tr>
+
| '''Examples'''
  <tr>
+
|
    <td>
+
* {{Code|math:tanh(100)}} returns {{Code|1}}.
      <b>Summary</b>
+
|}
    </td>
+
 
    <td>Returns the arc tangent of the argument.</td>
+
==math:crc32==
  </tr>
+
 
  <tr>
+
{| width='100%'
    <td>
+
|-
      <b>Rules</b>
+
| width='120' | '''Signature'''
    </td>
+
|<pre>math:crc32(
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the arc tangent of <code>$arg</code>, returned as an angle in radians in the range -π/2 to +π/2.<br />
+
  $string  as xs:string?
    </td>
+
) as xs:hexBinary?</pre>
  </tr>
+
|-
</table>
+
| '''Summary'''
+
|Calculates the CRC32 check sum of the given {{Code|$string}}.<br/>If an empty sequence is supplied, the empty sequence is returned.
<h2>math:atan2</h2>
+
|-
<table>
+
| '''Examples'''
  <tr>
+
|
    <td width="90">
+
* {{Code|math:crc32("")}} returns {{Code|'00000000'}}.
      <b>Signatures</b>
+
* {{Code|math:crc32("BaseX")}} returns {{Code|'4C06FC7F'}}.
    </td>
+
|}
    <td>
+
 
      <code>
+
=Changelog=
        <b>math:atan2</b>($arg1 as xs:double?, $arg2 as xs:double?) as xs:double?</code>
+
 
      <br />
+
; Version 9.1
    </td>
+
* Updated: {{Function||math:crc32}} can be called with empty sequence.
  </tr>
+
 
  <tr>
+
; Version 7.5
    <td>
+
* Moved: {{Code|math:random}} and {{Code|math:uuid}} have been moved to the [[Random Module]].
      <b>Summary</b>
+
 
    </td>
+
; Version 7.3
    <td>Returns the arc tangent of the first argument divided by the second argument, the result being in the range -π/2 to +π/2 radians.</td>
+
* Added: {{Function||math:crc32}} and {{Function||math:uuid}} have been adopted from the obsolete Utility Module.
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg1</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the arc tangent of <code>$arg1</code> divided by <code>$arg2</code>, returned as an angle in radians in the range -π to +π.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:pow</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:pow</b>($arg1 as xs:double?, $arg2 as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns the first argument raised to the power of the second argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg1</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the <code>$arg1</code> raised to the power of <code>$arg2</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:pow(2, 3)</code> returns <code>8</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:exp</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:exp</b>($arg as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns <i>e</i> raised to the power of the argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the value of <i>e</i> raised to the power of <code>$arg</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:exp(1)</code> returns <i>e</i>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:log</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:log</b>($arg as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns the natural logarithm of the argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the natural logarithm (base <i>e</i>) of <code>$arg</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:log(math:e())</code> returns <code>1</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:log10</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:log10</b>($arg as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns the base 10 logarithm of the argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the base 10 logarithm of <code>$arg</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:log(100)</code> returns <code>2</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:random</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:random</b>() as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns a random value.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>This function returns a random <code>xs:double</code> value between <code>0.0</code> and <code>1.0</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:sinh</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:sinh</b>($arg as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns the hyperbolic sine of the argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the hyperbolic sine of <code>$arg</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:sinh(0)</code> returns <code>0</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:cosh</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:cosh</b>($arg as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns the hyperbolic cosine of the argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the hyperbolic cosine of <code>$arg</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:cosh(0)</code> returns <code>1</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<h2>math:tanh</h2>
 
<table>
 
  <tr>
 
    <td width="90">
 
      <b>Signatures</b>
 
    </td>
 
    <td>
 
      <code>
 
        <b>math:tanh</b>($arg as xs:double?) as xs:double?</code>
 
      <br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Summary</b>
 
    </td>
 
    <td>Returns the hyperbolic tangent of the argument.</td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Rules</b>
 
    </td>
 
    <td>If <code>$arg</code> is the empty sequence, the function returns the empty sequence.<br />Otherwise the result is the hyperbolic tangent of <code>$arg</code>.<br />
 
    </td>
 
  </tr>
 
  <tr>
 
    <td>
 
      <b>Examples</b>
 
    </td>
 
    <td>The expression <code>math:tanh(100)</code> returns <code>1</code>.<br />
 
    </td>
 
  </tr>
 
</table>
 
 
<div id="footer">
 
  &copy; 2006-10 <a href="http://www.informatik.uni-konstanz.de/en/groups/dbis" target="top">
 
  BaseX; DBIS, U Konstanz &nbsp;</a>
 
  <!-- echo "Updated on ".(gmdate('Y/m/d', filectime($_SERVER[SCRIPT_NAME]))); -->
 
  <a href='http://twitter.com/home?status=http%3A%2F%2Fwww.basex.org' target='_blank'><img border='0' alt='twitter' src='gfx/twitter.png'/></a>
 
  <a href='http://facebook.com/sharer.php?u=http%3A%2F%2Fwww.basex.org' target='_blank'><img border='0' alt='facebook' src='gfx/facebook.png'/></a>
 
  <a href='http://del.icio.us/post?url=http%3A%2F%2Fwww.basex.org' target='_blank'><img border='0' alt='delicio.us' src='gfx/delicious.png'/></a>
 
<br/>&nbsp;
 

Latest revision as of 14: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
  • 2*math:pi() returns 6.283185307179586e0.
  • 60 * (math:pi() div 180) converts an angle of 60 degrees to radians.

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:pow(2, 3) returns 8.

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:exp(1) returns e.

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:log(math:e()) returns 1.

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
  • math:log(100) returns 2.

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
  • 5*math:e() returns 13.591409142295225.

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:sinh(0) returns 0.

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:cosh(0) returns 1.

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:tanh(100) returns 1.

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
  • math:crc32("") returns '00000000'.
  • math:crc32("BaseX") returns '4C06FC7F'.

Changelog[edit]

Version 9.1
  • Updated: math:crc32 can be called with empty sequence.
Version 7.5
  • Moved: math:random and math:uuid have been moved to the Random Module.
Version 7.3