Chapter 16. Working with Numbers

A variety of numerical calculations can be performed using XQuery. This chapter describes the four major numeric types, along with the operators and functions that act on numeric values. These include comparisons, arithmetic operations, and functions that operate on numeric values such as round and sum.

The Numeric Types

The four main numeric types supported in XQuery are xs:decimal, xs:integer, xs:float, and xs:double. All of the operations and functions that can be performed on these types of numeric values can also be performed on values whose types are restrictions of these types. This includes user-defined types that appear in a schema, as well as the built-in derived types such as xs:positiveInteger and xs:unsignedByte. For a complete list and explanation of these built-in derived types, see Appendix B.

The xs:decimal Type

The type xs:decimal represents a signed decimal number of implementation-defined precision. Numeric literals that contain only digits and a decimal point (no letter E or e) are considered decimal numbers, with the type xs:decimal. For example, 25.5 and 25.0 are xs:decimal values.

The xs:integer Type

The type xs:integer represents a signed integer. The limit on how large an xs:integer value can be is implementation-defined. Numeric literals that contain only digits (no decimal points or the letter E or e) are considered integers, with the type xs:integer. For example, 25 is an xs:integer value.

In the type hierarchy, xs:integer is derived by restriction from xs:decimal. Therefore, anywhere XQuery is expecting an xs:decimal value, an xs:integer value may be used in its place because of subtype substitution.

The xs:float and xs:double Types

The type xs:float is patterned after IEEE single-precision 32-bit floating-point numbers, and xs:double is patterned after IEEE double-precision 64-bit floating-point numbers. The representation of both xs:float and xs:double values is a mantissa (a decimal number) followed by the character E or e, followed by an exponent, which must be an integer. For example, 3E2 represents 3 × 102, or 300. Numeric literals that contain an E or e are considered to have the type xs:double.

In addition, the following values are represented: INF (infinity), -INF (negative infinity), and NaN (not a number).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.178