Contact us | Site map

XQuery 1.0 and XPath 2.0 Additional Functions 0.9

23 October 2008

This version:
http://www.xqsharp.com/TR/2008/xqsharp-functions-0.9/
Latest version:
http://www.xqsharp.com/TR/xqsharp-functions/
Previous version:
This is the first publication.
Editors:
Oliver Hallam, Clinical & Biomedical Computing Limited <oliver@cbcl.co.uk>
Tim Mills, Clinical & Biomedical Computing Limited <tim@cbcl.co.uk>
Copyright © 2008 Clinical and Biomedical Computing Limited

Abstract

This document defines functions on the datatypes defined in [XML Schema Part 2: Datatypes Second Edition] and the datatypes defined in [XQuery 1.0 and XPath 2.0 Data Model] for use in [XML Path Language (XPath) 2.0], [XQuery 1.0: An XML Query Language] and [XSL Transformations (XSLT) Version 2.0] and other related XML standards. These functions supplement those defined in [XQuery 1.0 and XPath 2.0 Functions and Operators].

Table of Contents

1 Introduction
2 Functions on Numbers
    2.1 General Mathematical Functions
        2.1.1 fn:exp
        2.1.2 fn:log
        2.1.3 fn:log10
        2.1.4 fn:pow
        2.1.5 fn:sqrt
    2.2 Trigonometric Functions
        2.2.1 fn:cos
        2.2.2 fn:sin
        2.2.3 fn:tan
    2.3 Inverse Trigonometric Functions
        2.3.1 fn:acos
        2.3.2 fn:asin
        2.3.3 fn:atan
        2.3.4 fn:atan2
    2.4 Hyperbolic Trigonometric Functions
        2.4.1 fn:cosh
        2.4.2 fn:sinh
        2.4.3 fn:tanh

Appendix

A References
    A.1 Normative


1 Introduction

The purpose of this document is to catalogue the functions available in the XQSharp implementation of XPath 2.0 and XML Query 1.0 in addition to the standard functions and operators specified in [XQuery 1.0 and XPath 2.0 Functions and Operators]. The exact syntax used to invoke these functions is specified in [XML Path Language (XPath) 2.0], [XQuery 1.0: An XML Query Language] and [XSL Transformations (XSLT) Version 2.0].

2 Functions on Numbers

2.1 General Mathematical Functions

The following functions are defined on arguments with xs:double? type. Each function returns a value of type xs:double?.

  • If the first argument is the empty sequence, the empty sequence is returned.

  • If any of the arguments is "NaN", "NaN" is returned.

FunctionMeaning
fn:exp Returns the value of e raised to the specified power.
fn:log Returns the natural (base e) logarithm of the argument.
fn:log10 Returns the common (base 10) logarithm of the argument.
fn:pow Returns the first argument raised to the power of the second argument.
fn:sqrt Returns the square root of the argument.

2.1.1 fn:exp

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

Summary: Returns the value of e raised to the power of $arg.

If the value of $arg is NaN, the xs:double value NaN is returned.

2.1.1.1 Examples
  • fn:exp ( 0 ) returns 1.

  • fn:exp ( 1 ) returns 2.718281828459045.

  • fn:exp ( xs:double('NaN') ) returns NaN.

2.1.2 fn:log

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

Summary: Returns the natural (base e) logarithm of $arg.

If the value of $arg is NaN, the xs:double value NaN is returned.

2.1.2.1 Examples
  • fn:log ( 2.718281828459045 ) returns 1.

  • fn:log ( 0 ) returns -INF.

  • fn:log ( xs:double('NaN') ) returns NaN.

2.1.3 fn:log10

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

Summary: Returns the common (base 10) logarithm of $arg.

If the value of $arg is NaN, the xs:double value NaN is returned.

2.1.3.1 Examples
  • fn:log10 ( 10 ) returns 1.

  • fn:log10 ( 0 ) returns -INF.

  • fn:log10 ( xs:double('NaN') ) returns NaN.

2.1.4 fn:pow

fn:pow($arg1 as xs:double?, $arg2 as xs:double) as xs:double?

Summary: Returns $arg1 raised to the power of $arg2.

If the value of $arg1 or $arg2 is NaN, the xs:double value NaN is returned.

2.1.4.1 Examples
  • fn:pow ( 10, 2 ) returns 100.

  • fn:pow ( 100, 0.5 ) returns 10.

  • fn:pow ( xs:double('INF'), 0 ) returns 1.

  • fn:pow ( xs:double('NaN'), 0 ) returns NaN.

2.1.5 fn:sqrt

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

Summary: Returns the square root of $arg.

If the value of $arg is NaN, or the value of $arg is negative, the xs:double value NaN is returned.

2.1.5.1 Examples
  • fn:sqrt ( 1 ) returns 1.

  • fn:sqrt ( 4 ) returns 2.

  • fn:sqrt ( -1 ) returns NaN.

  • fn:sqrt ( xs:double('INF') ) returns INF.

  • fn:sqrt ( xs:double('NaN') ) returns NaN.

2.2 Trigonometric Functions

The following functions are defined on arguments with xs:double? type. Each function returns a value of type xs:double?.

  • If the first argument is the empty sequence, the empty sequence is returned.

  • If any of the arguments is "NaN", "NaN" is returned.

FunctionMeaning
fn:cos Returns the cosine of the argument.
fn:sin Returns the sine of the argument.
fn:tan Returns the tangent of the argument.

2.2.1 fn:cos

fn:cos($arg as xs:double?) as xs:double?

Summary: Returns the cosine of $arg as an xs:double, where $arg is an angle measured in radians.

If the value of $arg is NaN, positive infinity or negative infinity, the xs:double value NaN is returned.

For values of $arg outside the range from approximately -9223372036854775295 to approximately 9223372036854775295, the fn:cos function returns $arg unchanged.

2.2.1.1 Examples
  • fn:cos ( 0 ) returns 1.

  • fn:cos ( xs:double('NaN') ) returns NaN.

2.2.2 fn:sin

fn:sin($arg as xs:double?) as xs:double?

Summary: Returns the sine of $arg as an xs:double, where $arg is an angle measured in radians

If the value of $arg is NaN, positive infinity or negative infinity, the xs:double value NaN is returned.

For values of $arg outside the range from approximately -9223372036854775295 to approximately 9223372036854775295, the fn:cos function returns $arg unchanged.

2.2.2.1 Examples
  • fn:sin ( 0 ) returns 0.

  • fn:sin ( xs:double('NaN') ) returns NaN.

2.2.3 fn:tan

fn:tan($arg as xs:double?) as xs:double?

Summary: Returns the tangent of $arg, where $arg is an xs:double angle measured in radians.

If the value of $arg is NaN, positive infinity or negative infinity, the xs:double value NaN is returned.

2.2.3.1 Examples
  • fn:tan ( 0 ) returns 1.

  • fn:tan ( xs:double('NaN') ) returns NaN.

2.3 Inverse Trigonometric Functions

The following functions are defined on arguments with xs:double? type. Each function returns a value of type xs:double?.

  • If the first argument is the empty sequence, the empty sequence is returned.

  • If any of the arguments is "NaN", "NaN" is returned.

FunctionMeaning
fn:acos Returns the arccosine (inverse cosine) of the argument.
fn:asin Returns the arcsine (inverse sine) of the argument.
fn:atan Returns the arctangent (inverse tangent) of the argument.
fn:atan2 Returns the arctangent (inverse tangent) of the argument first argument divided by the second.

2.3.1 fn:acos

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

Summary: Returns the arccosine (inverse cosine) of $arg as an xs:double angle measured in radians. The value returned is the value θ in the range 0 ≤ θ ≤ π such that cos(θ) = $arg.

If the value of $arg is NaN or is outside the range -1 to +1, the xs:double value NaN is returned.

2.3.1.1 Examples
  • fn:acos ( 1 ) returns 0.

  • fn:acos ( 2 ) returns NaN.

  • fn:acos ( xs:double('NaN') ) returns NaN.

2.3.2 fn:asin

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

Summary: Returns the arcsine (inverse sine) of $arg as an xs:double angle measured in radians. The value returned is the value θ in the range 0 ≤ θ ≤ π such that sin(θ) = $arg.

If the value of $arg is NaN or is outside the range -1 to +1, the xs:double value NaN is returned.

2.3.2.1 Examples
  • fn:asin ( 0 ) returns 0.

  • fn:asin ( 2 ) returns NaN.

  • fn:asin ( xs:double('NaN') ) returns NaN.

2.3.3 fn:atan

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

Summary: Returns the arctangent (inverse tangent) of $arg as an xs:double angle measured in radians. The value returned is the value θ in the range -π/2 ≤ θ ≤ π/2 such that tan(θ) = $arg.

If the argument is NaN, then the xs:double value NaN is returned.

2.3.3.1 Examples
  • fn:atan ( 0 ) returns 0.

  • fn:atan ( xs:double('INF') ) returns 1.5707963267949.

  • fn:atan ( xs:double('NaN') ) returns NaN.

2.3.4 fn:atan2

fn:atan2($arg1 as xs:double?, $arg2 as xs:double) as xs:double?

Summary: Returns the arctangent (inverse tangent) of $arg1 divided by $arg2 as an xs:double angle measured in radians. The value returned is the value θ in the range -π ≤ θ ≤ π such that $arg2 * tan(θ) = $arg1.

If $arg2 is positive then the result is in the range 0 ≤ θ < π. If $arg2 is negative then the result is in the range -π ≤ θ < 0.

If $arg2 is 0 then the result is 0 when $arg1 is non-negative, and π if $arg1 is negative.

If the value of $arg1 or $arg2 is NaN, or if both $arg1 and $arg2 are positive or negative infinity, the xs:double value NaN is returned.

2.3.4.1 Examples
  • fn:atan2 ( 0, 1 ) returns 0.

  • fn:atan2 ( 0, 0 ) returns 0.

  • fn:atan2 ( 0, xs:double('-0') ) returns 3.141592653589793.

  • fn:atan2 ( xs:double('-0'), 0 ) returns -0.

  • fn:atan2 ( xs:double('-0'), xs:double('-0') ) returns -3.141592653589793.

  • fn:atan2 ( 1, xs:double('INF') ) returns 0.

  • fn:atan2 ( xs:double('NaN'), 1) returns NaN.

  • fn:atan2 ( xs:double('INF'), xs:double('-INF') ) returns NaN.

2.4 Hyperbolic Trigonometric Functions

The following functions are defined on arguments with xs:double? type. Each function returns a value of type xs:double?.

  • If the first argument is the empty sequence, the empty sequence is returned.

  • If any of the arguments is "NaN", "NaN" is returned.

FunctionMeaning
fn:cosh Returns the hyperbolic cosine of the argument.
fn:sinh Returns the hyperbolic sine of the argument.
fn:tanh Returns the hyperbolic tangent of the argument.

2.4.1 fn:cosh

fn:cosh($arg as xs:double?) as xs:double?

Summary: Returns the hyperbolic cosine of $arg.

If the value of $arg is NaN, the xs:double value NaN is returned.

2.4.1.1 Examples
  • fn:cosh ( xs:double('NaN') ) returns NaN.

  • fn:cosh ( 0 ) returns 1.

  • fn:cosh ( xs:double('-INF') ) returns INF.

2.4.2 fn:sinh

fn:sinh($arg as xs:double?) as xs:double?

Summary: Returns the hyperbolic sine of $arg.

If the value of $arg is NaN, the xs:double value NaN is returned.

2.4.2.1 Examples
  • fn:sinh ( xs:double('NaN') ) returns NaN.

  • fn:sinh ( 0 ) returns 0.

  • fn:sinh ( xs:double('INF') ) returns INF.

2.4.3 fn:tanh

fn:tanh($arg as xs:double?) as xs:double?

Summary: Returns the hyperbolic tangent of $arg.

If the value of $arg is NaN, the xs:double value NaN is returned.

If the value of $arg is positive or negative zero, positive or negative zero respectively is returned.

2.4.3.1 Examples
  • fn:tanh ( xs:double('NaN') ) returns NaN.

  • fn:tanh ( xs:double('INF') ) returns 1.

  • fn:tanh ( xs:double('-0') ) returns -0.

A References

A.1 Normative

XML Path Language (XPath) 2.0
World Wide Web Consortium. XML Path Language (XPath) Version 2.0. Available at: http://www.w3.org/TR/xpath20/
XSL Transformations (XSLT) Version 2.0
World Wide Web Consortium. XSL Transformations Version 2.0. Available at: http://www.w3.org/TR/xslt20/
XQuery 1.0 and XPath 2.0 Data Model
World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Data Model. Available at: http://www.w3.org/TR/query-datamodel/
XQuery 1.0 and XPath 2.0 Functions and Operators
World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Functions and Operators. Available at: http://www.w3.org/TR/xpath-functions/
XQuery 1.0: An XML Query Language
World Wide Web Consortium. XQuery 1.0: An XML Query Language. Available at: http://www.w3.org/TR/xquery/
XML Schema Part 2: Datatypes Second Edition
XML Schema Part 2: Datatypes Second Edition, Oct. 28 2004. Available at: http://www.w3.org/TR/xmlschema-2/