Difference between revisions of "Math Module"
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:pi</b>() as xs:double</code | + | |<code><b>math:pi</b>() as xs:double</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the <code>xs:double</code> value of the mathematical constant π whose lexical representation is 3.141592653589793. | + | |Returns the <code>xs:double</code> value of the mathematical constant π whose lexical representation is 3.141592653589793. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>2*math:pi()</code> returns <code>6.283185307179586e0</code>. | ||
+ | * <code>60 * (math:pi() div 180)</code> converts an angle of 60 degrees to radians. | ||
|} | |} | ||
Line 18: | Line 20: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:e</b>() as xs:double</code | + | |<code><b>math:e</b>() as xs:double</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the <code>xs:double</code> value of the mathematical constant <i>e</i> whose lexical representation is 2.718281828459045. | + | |Returns the <code>xs:double</code> value of the mathematical constant <i>e</i> whose lexical representation is 2.718281828459045. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>5*math:e()</code> returns <code>13.591409142295225</code>. | ||
|} | |} | ||
Line 31: | Line 34: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:sqrt</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:sqrt</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the square root of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the <code>xs:double</code> value of the mathematical square root of <code>$arg</code>. | + | |Returns the square root of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the <code>xs:double</code> value of the mathematical square root of <code>$arg</code>. |
|} | |} | ||
Line 41: | Line 44: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:sin</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:sin</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the sine of the <code>$arg</code>, expressed in radians.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the sine of <code>$arg</code>, treated as an angle in radians. | + | |Returns the sine of the <code>$arg</code>, expressed in radians.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the sine of <code>$arg</code>, treated as an angle in radians. |
|} | |} | ||
Line 51: | Line 54: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:cos</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:cos</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the cosine of <code>$arg</code>, expressed in radians.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the cosine of <code>$arg</code>, treated as an angle in radians. | + | |Returns the cosine of <code>$arg</code>, expressed in radians.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the cosine of <code>$arg</code>, treated as an angle in radians. |
|} | |} | ||
Line 61: | Line 64: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:tan</b>($ as xs:double?) as xs:double?</code | + | |<code><b>math:tan</b>($ as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the tangent of <code>$arg</code>, expressed in radians.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the tangent of <code>$arg</code>, treated as an angle in radians. | + | |Returns the tangent of <code>$arg</code>, expressed in radians.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the tangent of <code>$arg</code>, treated as an angle in radians. |
|} | |} | ||
Line 71: | Line 74: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:asin</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:asin</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the arc sine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc sine of <code>$arg</code>, returned as an angle in radians in the range -π/2 to +π/2. | + | |Returns the arc sine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc sine of <code>$arg</code>, returned as an angle in radians in the range -π/2 to +π/2. |
|} | |} | ||
Line 81: | Line 84: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:acos</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:acos</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the arc cosine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc cosine of <code>$arg</code>, returned as an angle in radians in the range 0 to +π. | + | |Returns the arc cosine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc cosine of <code>$arg</code>, returned as an angle in radians in the range 0 to +π. |
|} | |} | ||
Line 91: | Line 94: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:atan</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:atan</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the arc tangent of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc tangent of <code>$arg</code>, returned as an angle in radians in the range -π/2 to +π/2. | + | |Returns the arc tangent of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the arc tangent of <code>$arg</code>, returned as an angle in radians in the range -π/2 to +π/2. |
|} | |} | ||
Line 101: | Line 104: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:atan2</b>($arg1 as xs:double?, $arg2 as xs:double) as xs:double?</code | + | |<code><b>math:atan2</b>($arg1 as xs:double?, $arg2 as xs:double) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the arc tangent of <code>$arg1</code> divided by <code>$arg2</code>, the result being in the range -π/2 to +π/2 radians.<br/>If <code>$arg1</code> is the empty sequence, the empty sequence is returned.<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 +π. | + | |Returns the arc tangent of <code>$arg1</code> divided by <code>$arg2</code>, the result being in the range -π/2 to +π/2 radians.<br/>If <code>$arg1</code> is the empty sequence, the empty sequence is returned.<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 +π. |
|} | |} | ||
Line 111: | Line 114: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:pow</b>($arg1 as xs:double?, $arg2 as xs:double) as xs:double?</code | + | |<code><b>math:pow</b>($arg1 as xs:double?, $arg2 as xs:double) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns <code>$arg1</code> raised to the power of <code>$arg2</code>.<br/>If <code>$arg1</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the <code>$arg1</code> raised to the power of <code>$arg2</code>. | + | |Returns <code>$arg1</code> raised to the power of <code>$arg2</code>.<br/>If <code>$arg1</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the <code>$arg1</code> raised to the power of <code>$arg2</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:pow(2, 3)</code> returns <code>8</code>. | ||
|} | |} | ||
Line 124: | Line 128: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:exp</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:exp</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns <i>e</i> raised to the power of <code>$arg</code>.<br/>If <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>$arg</code>. | + | |Returns <i>e</i> raised to the power of <code>$arg</code>.<br/>If <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>$arg</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:exp(1)</code> returns <i>e</i>. | ||
|} | |} | ||
Line 137: | Line 142: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:log</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:log</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the natural logarithm of <code>$arg</code>.<br/>If <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>$arg</code>. | + | |Returns the natural logarithm of <code>$arg</code>.<br/>If <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>$arg</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:log(math:e())</code> returns <code>1</code>. | ||
|} | |} | ||
Line 150: | Line 156: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:log10</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:log10</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the base 10 logarithm of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the base 10 logarithm of <code>$arg</code>. | + | |Returns the base 10 logarithm of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the base 10 logarithm of <code>$arg</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:log(100)</code> returns <code>2</code>. | ||
|} | |} | ||
Line 163: | Line 170: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:random</b>() as xs:double?</code | + | |<code><b>math:random</b>() as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns a random <code>xs:double</code> value between <code>0.0</code> and <code>1.0</code>. | + | |Returns a random <code>xs:double</code> value between <code>0.0</code> and <code>1.0</code>. |
|} | |} | ||
Line 173: | Line 180: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:sinh</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:sinh</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the hyperbolic sine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic sine of <code>$arg</code>. | + | |Returns the hyperbolic sine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic sine of <code>$arg</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:sinh(0)</code> returns <code>0</code>. | ||
|} | |} | ||
Line 186: | Line 194: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:cosh</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:cosh</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the hyperbolic cosine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic cosine of <code>$arg</code>. | + | |Returns the hyperbolic cosine of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic cosine of <code>$arg</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:cosh(0)</code> returns <code>1</code>. | ||
|} | |} | ||
Line 199: | Line 208: | ||
|- | |- | ||
| valign='top' width='90' | '''Signatures''' | | valign='top' width='90' | '''Signatures''' | ||
− | |<code><b>math:tanh</b>($arg as xs:double?) as xs:double?</code | + | |<code><b>math:tanh</b>($arg as xs:double?) as xs:double?</code> |
|- | |- | ||
| valign='top' | '''Summary''' | | valign='top' | '''Summary''' | ||
− | |Returns the hyperbolic tangent of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic tangent of <code>$arg</code>. | + | |Returns the hyperbolic tangent of <code>$arg</code>.<br/>If <code>$arg</code> is the empty sequence, the empty sequence is returned.<br />Otherwise the result is the hyperbolic tangent of <code>$arg</code>. |
|- | |- | ||
| valign='top' | '''Examples''' | | valign='top' | '''Examples''' | ||
− | | | + | | |
+ | * <code>math:tanh(100)</code> returns <code>1</code>. | ||
|} | |} | ||
[[Category:XQuery]] | [[Category:XQuery]] |
Revision as of 16:25, 23 April 2011
The math module defines XQuery Functions to perform mathematical operations, such as pi
, asin
and acos
. All functions are preceded by the math:
prefix, which is linked to the http://www.w3.org/2005/xpath-functions/math
namespace. Some of the functions have also been specified in the Functions and Operators Specification of the upcoming XQuery 3.0 Recommendation.
Contents
math:pi
Signatures | math:pi() as xs:double
|
Summary | Returns the xs:double value of the mathematical constant π whose lexical representation is 3.141592653589793.
|
Examples |
|
math:e
Signatures | math:e() as xs:double
|
Summary | Returns the xs:double value of the mathematical constant e whose lexical representation is 2.718281828459045.
|
Examples |
|
math:sqrt
Signatures | 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
Signatures | 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
Signatures | 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
Signatures | math:tan($ 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
Signatures | 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
Signatures | 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
Signatures | 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
Signatures | 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
Signatures | 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
Signatures | 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
Signatures | 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
Signatures | 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:random
Signatures | math:random() as xs:double?
|
Summary | Returns a random xs:double value between 0.0 and 1.0 .
|
math:sinh
Signatures | 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
Signatures | 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
Signatures | 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 |
|