Difference between revisions of "Math Module"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | The math [[Module Library|XQuery Module]] defines functions to perform mathematical operations, such as | + | 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 [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= | =Conventions= | ||
− | All functions in this module are assigned to the | + | All functions in this module are assigned to the {{Code|http://www.w3.org/2005/xpath-functions/math}} namespace, which is statically bound to the {{Code|math}} prefix.<br/> |
=Functions= | =Functions= | ||
Line 11: | Line 11: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:pi||xs:double}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the | + | |Returns the {{Code|xs:double}} value of the mathematical constant π whose lexical representation is 3.141592653589793. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|2*math:pi()}} returns {{Code|6.283185307179586e0}}. |
− | * | + | * {{Code|60 * (math:pi() div 180)}} converts an angle of 60 degrees to radians. |
|} | |} | ||
Line 26: | Line 26: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:e||xs:double}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the | + | |Returns the {{Code|xs:double}} value of the mathematical constant <i>e</i> whose lexical representation is 2.718281828459045. |
|- | |- | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * | + | * {{Code|5*math:e()}} returns {{Code|13.591409142295225}}. |
|} | |} | ||
Line 40: | Line 40: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:sqrt|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the square root of | + | |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}}. |
|} | |} | ||
Line 50: | Line 50: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:sin|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the sine of the | + | |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. |
|} | |} | ||
Line 60: | Line 60: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:cos|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the cosine of | + | |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. |
|} | |} | ||
Line 70: | Line 70: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:tan|$ as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the tangent of | + | |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. |
|} | |} | ||
Line 80: | Line 80: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:asin|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the arc sine of | + | |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. |
|} | |} | ||
Line 90: | Line 90: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:acos|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the arc cosine of | + | |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 +π. |
|} | |} | ||
Line 100: | Line 100: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:atan|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the arc tangent of | + | |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. |
|} | |} | ||
Line 110: | Line 110: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:atan2|$arg1 as xs:double?, $arg2 as xs:double|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the arc tangent of | + | |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 +π. |
|} | |} | ||
Line 120: | Line 120: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:pow|$arg1 as xs:double?, $arg2 as xs:double|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns | + | |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''' | ||
| | | | ||
− | * | + | * {{Code|math:pow(2, 3)}} returns {{Code|8}}. |
|} | |} | ||
Line 134: | Line 134: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:exp|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns <i>e</i> raised to the power of | + | |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''' | ||
| | | | ||
− | * | + | * {{Code|math:exp(1)}} returns <i>e</i>. |
|} | |} | ||
Line 148: | Line 148: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:log|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the natural logarithm of | + | |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''' | ||
| | | | ||
− | * | + | * {{Code|math:log(math:e())}} returns {{Code|1}}. |
|} | |} | ||
Line 162: | Line 162: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:log10|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the base 10 logarithm of | + | |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''' | ||
| | | | ||
− | * | + | * {{Code|math:log(100)}} returns {{Code|2}}. |
|} | |} | ||
Line 176: | Line 176: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:random||xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns a random | + | |Returns a random {{Code|xs:double}} value between {{Code|0.0}} and {{Code|1.0}}. |
|} | |} | ||
Line 186: | Line 186: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:sinh|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the hyperbolic sine of | + | |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''' | ||
| | | | ||
− | * | + | * {{Code|math:sinh(0)}} returns {{Code|0}}. |
|} | |} | ||
Line 200: | Line 200: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:cosh|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the hyperbolic cosine of | + | |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''' | ||
| | | | ||
− | * | + | * {{Code|math:cosh(0)}} returns {{Code|1}}. |
|} | |} | ||
Line 214: | Line 214: | ||
|- | |- | ||
| width='90' | '''Signatures''' | | width='90' | '''Signatures''' | ||
− | | | + | |{{Func|math:tanh|$arg as xs:double?|xs:double?}} |
|- | |- | ||
| '''Summary''' | | '''Summary''' | ||
− | |Returns the hyperbolic tangent of | + | |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}}. |
|} | |} | ||
[[Category:XQuery]] | [[Category:XQuery]] |
Revision as of 16:13, 26 May 2012
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.
Contents
Conventions
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.
Functions
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 |
|