Main Page » XQuery » Functions » Math Functions

# Math Functions

This module defines functions to perform mathematical operations, such as `pi`, `asin` and `acos`. Most functions are described in detail in the XQuery Functions and Operators Specification, and some functions have been added.

Removed: `math:crc-32` is not part of the new XQuery 4 standard function fn:hash.

## 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`

Signature `math:pi() as xs:double` Returns the value of the mathematical constant π. ``math:pi()`` Result: `3.141592653589793e0```60 * (math:pi() div 180)``Converts an angle of 60 degrees to radians.

### `math:e`

Signature `math:e() as xs:double` Returns the `xs:double` value of the mathematical constant e. ``math:e()`` Result: `2.718281828459045e0`

### `math:sqrt`

Signature ```math:sqrt( \$value as xs:double? ) as xs:double?``` Returns the square root of `\$value`.

### `math:pow`

Signature ```math:pow( \$x as xs:double?, \$y as xs:double ) as xs:double?``` Returns `\$x` raised to the power of `\$y`. ``math:pow(2, 3)`` Result: `8`

### `math:exp`

Signature ```math:exp( \$value as xs:double? ) as xs:double?``` Returns e raised to the power of `\$value`. ``math:exp(1)``Returns e.

### `math:log`

Signature ```math:log( \$value as xs:double? ) as xs:double?``` Returns the natural logarithm (base e) of `\$value`. ``math:log(math:e())`` Result: `1`

### `math:log10`

Signature ```math:log10( \$value as xs:double? ) as xs:double?``` Returns the base 10 logarithm of `\$value`. ``math:log(100)`` Result: `4.605170185988092e0`

### `math:sin`

Signature ```math:sin( \$radians as xs:double? ) as xs:double?``` Returns the sine of `\$radians`, expressed as an angle in radians.

### `math:cos`

Signature ```math:cos( \$radians as xs:double? ) as xs:double?``` Returns the cosine of `\$radians`, expressed as an angle in radians.

### `math:tan`

Signature ```math:tan( \$radians as xs:double? ) as xs:double?``` Returns the tangent of `\$radians`, expressed as an angle in radians.

### `math:asin`

Signature ```math:asin( \$value as xs:double? ) as xs:double?``` Returns the arc sine of `\$value`, expressed as an angle in radians in the range –π/2 to +π/2.

### `math:acos`

Signature ```math:acos( \$value as xs:double? ) as xs:double?``` Returns the arc cosine of `\$value`, expressed as an angle in radians in the range 0 to +π.

### `math:atan`

Signature ```math:atan( \$value as xs:double? ) as xs:double?``` Returns the arc tangent of `\$value`, expressed as an angle in radians in the range –π/2 to +π/2.

### `math:atan2`

Signature ```math:atan2( \$x as xs:double?, \$y as xs:double ) as xs:double?``` Returns the arc tangent of `\$x` divided by `\$y`, expressed as an angle in radians in the range –π to +π.

### `math:sinh`

Signature ```math:sinh( \$value as xs:double? ) as xs:double?``` Returns the hyperbolic sine of `\$value` ``math:sinh(0)`` Result: `0`

### `math:cosh`

Signature ```math:cosh( \$value as xs:double? ) as xs:double?``` Returns the hyperbolic cosine of `\$value`. ``math:cosh(0)`` Result: `1`

### `math:tanh`

Signature ```math:tanh( \$value as xs:double? ) as xs:double?``` Returns the hyperbolic tangent of `\$value`. ``math:tanh(100)`` Result: `1`

## Changelog

Version 11.0
• Updated: `math:e`, `math:sinh`, `math:cosh` and `math:tanh` are now part of the standard.
• Removed: `math:crc32` in favor of `fn:hash`.
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 Functions.
Version 7.3
• Added: `math:crc32` and `math:uuid` have been adopted from the obsolete Utility Module.

⚡Generated with XQuery