abs function

The fn:abs function returns the absolute value of a numeric value.

Syntax

Read syntax diagramSkip visual syntax diagramfn:abs( numeric-value)
numeric-value
An atomic value or an empty sequence.
If numeric-value is an atomic value, it has one of the following types:
  • xs:float
  • xs:double
  • xs:decimal
  • xs:integer
  • A type that is derived from any of the previously listed types
  • xdt:untypedAtomic
If numeric-value has the xdt:untypedAtomic data type, it is converted to an xs:double value.

Returned value

If numeric-value is not the empty sequence, the returned value is the absolute value of numeric-value.

If numeric-value is the empty sequence, fn:abs returns the empty sequence.

The data type of the returned value depends on the data type of numeric-value:
  • If numeric-value is xs:float, xs:double, xs:decimal, or xs:integer, the value that is returned has the same type as numeric-value.
  • If numeric-value has a data type that is derived from xs:float, xs:double, xs:decimal, or xs:integer, the value that is returned has the direct parent data type of numeric-value.
  • If numeric-value has the xdt:untypedAtomic data type, the value that is returned has the xs:double data type.

Example

The following function returns the absolute value of -10.5.
fn:abs(-10.5)

The returned value is 10.5.