http://www.w3.org/2005/xpath-functions/math

View as XML or JSON.

This module contains all the functions part of the W3C XPath and XQuery Functions and Operators 3.0 section "4.7 Trigonometric and exponential functions".

Function Summary

acos ($arg as xs:double?) as xs:double? external

Returns the arc cosine of the argument, the result being in the range zero to + π radians.

asin ($arg as xs:double?) as xs:double? external

Returns the arc sine of the argument, the result being in the range - π /2 to + π /2 radians.

atan ($arg as xs:double?) as xs:double? external

Returns the arc tangent of the argument, the result being in the range - π /2 to + π /2 radians.

atan2 ($y as xs:double, $x as xs:double) as xs:double external

Returns the angle in radians subtended at the origin by the point on a plane with coordinates (x, y) and the positive x-axis, the result being in the range - π to + π .

cos ($theta as xs:double?) as xs:double? external

Returns the cosine of the argument, expressed in radians.

exp ($arg as xs:double?) as xs:double? external

Returns the value of e x .

exp10 ($arg as xs:double?) as xs:double? external

Returns the value of 10 x .

log ($arg as xs:double?) as xs:double? external

Returns the natural logarithm of the argument.

log10 ($arg as xs:double?) as xs:double? external

Returns the base-ten logarithm of the argument.

pi () as xs:double external

Returns an approximation to the mathematical constant π .

pow ($x as xs:double?, $y as numeric) as xs:double? external

Returns the result of raising the first argument to the power of the second.

sin ($theta as xs:double?) as xs:double? external

Returns the sine of the argument, expressed in radians.

sqrt ($arg as xs:double?) as xs:double? external

Returns the non-negative square root of the argument.

tan ($theta as xs:double?) as xs:double? external

Returns the tangent of the argument, expressed in radians.

Functions

acos#1

declare  function math:acos($arg as xs:double?) as xs:double? external

Returns the arc cosine of the argument, the result being in the range zero to +π radians.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the arc cosine of $θ, treated as an angle in radians, as defined in the specification of the acos function applied to 64-bit binary floating point values.

The treatment of the invalidOperation exception is defined in .

If $arg is NaN, or if its absolute value is greater than one, then the result is NaN.

In other cases the result is an xs:double value representing an angle θ in radians in the range 0 <= $θ <= +π.

Parameters

arg as xs:double

Returns

xs:double?

asin#1

declare  function math:asin($arg as xs:double?) as xs:double? external

Returns the arc sine of the argument, the result being in the range -π/2 to +π/2 radians.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the arc sine of $θ, treated as an angle in radians, as defined in the specification of the asin function applied to 64-bit binary floating point values.

The treatment of the invalidOperation and underflow exceptions is defined in .

If $arg is positive or negative zero, the result is $arg.

If $arg is NaN, or if its absolute value is greater than one, then the result is NaN.

In other cases the result is an xs:double value representing an angle θ in radians in the range -π/2 <= $θ <= +π/2.

Parameters

arg as xs:double

Returns

xs:double?

atan#1

declare  function math:atan($arg as xs:double?) as xs:double? external

Returns the arc tangent of the argument, the result being in the range -π/2 to +π/2 radians.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the arc tangent of $θ, treated as an angle in radians, as defined in the specification of the atan function applied to 64-bit binary floating point values.

The treatment of the underflow exception is defined in .

If $arg is positive or negative zero, the result is $arg.

If $arg is NaN then the result is NaN.

In other cases the result is an xs:double value representing an angle θ in radians in the range -π/2 <= $θ <= +π/2.

Parameters

arg as xs:double

Returns

xs:double?

atan2#2

declare  function math:atan2($y as xs:double, $x as xs:double) as xs:double external

Returns the angle in radians subtended at the origin by the point on a plane with coordinates (x, y) and the positive x-axis, the result being in the range -π to +π.

This function is deterministic, context-independent, and focus-independent.

The result is the value of atan2(y, x) as defined in the specification of the atan2 function applied to 64-bit binary floating point values.

The treatment of the underflow exception is defined in .

If either argument is NaN then the result is NaN.

If $y is positive and $x is positive and finite, then (subject to rules for overflow, underflow and approximation) the value of atan2($y, $x) is atan($y div $x).

If $y is positive and $x is negative and finite, then (subject to the same caveats) the value of atan2($y, $x) is π - atan($y div $x).

Some results for special values of the arguments are shown in the examples below.

Parameters

y as xs:double
x as xs:double

Returns

xs:double

cos#1

declare  function math:cos($theta as xs:double?) as xs:double? external

Returns the cosine of the argument, expressed in radians.

This function is deterministic, context-independent, and focus-independent.

If $θ is the empty sequence, the function returns the empty sequence.

If $θ is positive or negative infinity, or NaN, then the result is NaN.

Otherwise the result is the cosine of $θ, treated as an angle in radians, as defined in the specification of the cos function applied to 64-bit binary floating point values.

The treatment of the invalidOperation exception is defined in .

If $θ is positive or negative zero, the result is $θ.

If $θ is positive or negative infinity, or NaN, then the result is NaN.

Otherwise the result is always in the range -1.0e0 to +1.0e0

Parameters

theta as xs:double

Returns

xs:double?

exp#1

declare  function math:exp($arg as xs:double?) as xs:double? external

Returns the value of ex.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the mathematical constant e raised to the power of $arg, as defined in the specification of the exp function applied to 64-bit binary floating point values.

The treatment of overflow and underflow is defined in .

Parameters

arg as xs:double

Returns

xs:double?

exp10#1

declare  function math:exp10($arg as xs:double?) as xs:double? external

Returns the value of 10x.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is ten raised to the power of $arg, as defined in the specification of the exp10 function applied to 64-bit binary floating point values.

The treatment of overflow and underflow is defined in .

Parameters

arg as xs:double

Returns

xs:double?

log#1

declare  function math:log($arg as xs:double?) as xs:double? external

Returns the natural logarithm of the argument.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the natural logarithm of $arg, as defined in the specification of the log function applied to 64-bit binary floating point values.

The treatment of divideByZero and invalidOperation exceptions is defined in . The effect is that if the argument is less than or equal to zero, the result is NaN.

Parameters

arg as xs:double

Returns

xs:double?

log10#1

declare  function math:log10($arg as xs:double?) as xs:double? external

Returns the base-ten logarithm of the argument.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the base-10 logarithm of $arg, as defined in the specification of the log10 function applied to 64-bit binary floating point values.

The treatment of divideByZero and invalidOperation exceptions is defined in . The effect is that if the argument is less than or equal to zero, the result is NaN.

Parameters

arg as xs:double

Returns

xs:double?

pi#0

declare  function math:pi() as xs:double external

Returns an approximation to the mathematical constant π.

This function is deterministic, context-independent, and focus-independent.

This function returns the xs:double value whose lexical representation is 3.141592653589793e0

The expression 2*math:pi() returns 6.283185307179586e0.

The expression 60 * (math:pi() div 180) converts an angle of 60 degrees to radians.

Parameters

Returns

xs:double

pow#2

declare  function math:pow($x as xs:double?, $y as numeric) as xs:double? external

Returns the result of raising the first argument to the power of the second.

This function is deterministic, context-independent, and focus-independent.

If $x is the empty sequence, the function returns the empty sequence.

If $y is an instance of xs:integer, the result is $x raised to the power of $y as defined in the specification of the pown function applied to a 64-bit binary floating point value and an integer.

Otherwise $y is converted to an xs:double by numeric promotion, and the result is the value of $x raised to the power of $y as defined in the specification of the pow function applied to two 64-bit binary floating point values.

The treatment of the divideByZero and invalidOperation exceptions is defined in . Some of the consequences are illustrated in the examples below.

Parameters

x as xs:double
y as numeric

Returns

xs:double?

sin#1

declare  function math:sin($theta as xs:double?) as xs:double? external

Returns the sine of the argument, expressed in radians.

This function is deterministic, context-independent, and focus-independent.

If $θ is the empty sequence, the function returns the empty sequence.

Otherwise the result is the sine of $θ, treated as an angle in radians, as defined in the specification of the sin function applied to 64-bit binary floating point values.

The treatment of the invalidOperation and underflow exceptions is defined in .

If $θ is positive or negative zero, the result is $θ.

If $θ is positive or negative infinity, or NaN, then the result is NaN.

Otherwise the result is always in the range -1.0e0 to +1.0e0

Parameters

theta as xs:double

Returns

xs:double?

sqrt#1

declare  function math:sqrt($arg as xs:double?) as xs:double? external

Returns the non-negative square root of the argument.

This function is deterministic, context-independent, and focus-independent.

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise the result is the mathematical non-negative square root of $arg as defined in the specification of the squareRoot function applied to 64-bit binary floating point values.

The treatment of the invalidOperation exception is defined in . The effect is that if the argument is less than zero, the result is NaN.

If $arg is positive or negative zero, positive infinity, or NaN, then the result is $arg. (Negative zero is the only case where the result can have negative sign)

Parameters

arg as xs:double

Returns

xs:double?

tan#1

declare  function math:tan($theta as xs:double?) as xs:double? external

Returns the tangent of the argument, expressed in radians.

This function is deterministic, context-independent, and focus-independent.

If $θ is the empty sequence, the function returns the empty sequence.

Otherwise the result is the tangent of $θ, treated as an angle in radians, as defined in the specification of the tan function applied to 64-bit binary floating point values.

The treatment of the invalidOperation and underflow exceptions is defined in .

If $θ is positive or negative infinity, or NaN, then the result is NaN.

Parameters

theta as xs:double

Returns

xs:double?