xs:float

The primitive type xs:float is patterned after an IEEE single-precision 32-bit floating-point number. The lexical representation is a mantissa (a decimal number) followed, optionally, by the letter E (in upper- or lowercase), followed by an integer exponent. For example, 3E2 represents 3 × 102, or 300. In addition, there are three special values: INF, (infinity), -INF (negative infinity), and NaN (not a number).

Table B-10 lists some values of the xs:float type.

Table B-10. Values of the xs:float type

Values

Explanation

Valid

 
-5E12
 
44.56E5
 
+23.2e−2
 
12
 
+3.5

Any value valid for xs:decimal is also valid for xs:float and xs:double

−0

Negative zero

INF

Positive infinity

NaN

Not a number

Invalid

 
−5E3.5

The exponent must be an integer

 37E

An exponent must be specified if E is present

 

An empty value or zero-length string is not permitted

XQuery makes a distinction between positive and negative zero values for the xs:float type. 0 and −0 are considered to be equal but separate values.

The implementation has some flexibility regarding how to handle overflow or underflow occurs during arithmetic operations on xs:float values. The processor may raise an error. Alternatively, in an overflow situation, it may return INF, -INF, or the largest or smallest possible value. For underflow, it may return the closest possible value to zero.

Casting xs:float Values

Values of type xs:float can be cast to and from any of the other numeric types. Casting among numeric types is straightforward if the value is in the value space of both types. For example, casting an xs:float value 12.5E0 to xs:decimal results in a value 12.5 whose type is xs:decimal.

However, some xs:float values are either too large or are otherwise not represented in the value spaces of xs:decimal or xs:integer. See the descriptions of these types for more information.

Additionally, some special cases apply when casting xs:double values to xs:float. Values that are too large to be represented by xs:float are cast to INF, values that are too small are cast to -INF, and values that would cause underflow are cast to 0.

Values of type xs:float can also be cast to and from xs:string, xs:untypedAtomic, and xs:boolean. When cast to xs:string, if the value is between 0.000001 (inclusive) and 1000000 (exclusive), the value is represented as a decimal. It will have no exponent, no positive sign, and no leading or trailing zeros, except that there will always be at least one digit before the decimal point. If there is no fractional part, the decimal point is omitted. If the value is outside that range, it is represented using an exponent as shown in the first three examples in Table B-10.

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

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