MXQuery supports the same mathematical functions as Zorba, using the same namespace and modules.

In addition, it supports a function a general exponentiation function pow(). For convenience, this function is placed into the same module as the other math functions.

  1.  
  2. import module namespace math =
  3.   "http://www.zorba-xquery.com/zorba/math-functions";
  4.  
  5. math:sqrt ($arg as numeric?) as numeric?
  6.  
  7. math:exp ($arg as xs:double) as xs:double
  8. math:log ($arg as xs:double) as xs:double
  9. math:sin ($arg as xs:double) as xs:double
  10. math:cos ($arg as xs:double) as xs:double
  11. math:tan ($arg as xs:double) as xs:double
  12. math:asin ($arg as xs:double) as xs:double
  13. math:acos ($arg as xs:double) as xs:double
  14. math:atan ($arg as xs:double) as xs:double
  15.  
  16. math:pow($base as numeric?, exp as as numeric?) as as xs:double

For sqrt, if type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.

All the transcendental functions (exp, log, sin, cos, tan, asin, acos, atan) take double arguments and return doubles.

For arguments outside their domain, the following functions return NaN: sqrt and ln, for negative arguments; and asin and acos, for arguments outside [-1, 1].