∟"float" and "double" Datatype Values and Representations
This section describes the built-in primitive datatypes, 'float' and 'double' that represents single-precision (32-bit) and double-precision (64-bit) floating-point numbers. Leading and trailing whitespaces allowed and trimmed.
XSD 1.1 supports 2 built-in datatypes, "float" and "double", to represent floating-point numbers
defined in the "IEEE 754-2008" standard
with these rules:
The value space of "float" is all single-precision 32-bit floating point numbers.
The lexical space of "float" is representations of (decimal)(e|E)(integer) pattern
and specal keywords: "INF", "-INF" and "NaN".
When mapping a "float" lexical presentation to "float" value, truncation will be applied.
The value space of "double" is all double-precision 64-bit floating point numbers.
The lexical space of "double" is the same as "float".
When mapping a "double" lexical presentation to "double" value, truncation will be applied.
Leading and trailing whitespaces allowed and trimmed.
To verify these rules, I wrote this simple XSD document that uses "float" and "double" datatypes
to declare XML elements:
Here is a sample XML document that can be used to test these declarations:
<?xml version="1.1"?>
<!-- float_double_datatype_test.xml
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<Float_Double_Datatype_Test>
<!-- 3 valid "Float" elements -->
<Float> 123 </Float>
<Float> -1234567890.1234567890e1234567890 </Float>
<Float> +1234567890.1234567890E-12345678901234567890 </Float>
<Float> -INF </Float>
<Float> NaN </Float>
<!-- 3 invalid "Float" elements -->
<Float> -1.23e1.23 </Float>
<!-- 3 valid "Double" elements -->
<Double> 1844674407370955161518446744073709551615 </Double>
<Double> -1234567890.1234567890e1234567890 </Double>
<Double> +1234567890.1234567890E-1234567890 </Double>
<Double> INF </Double>
<Double> NaN </Double>
<!-- 3 invalid "Double" elements -->
<Double> +INF </Double>
</Float_Double_Datatype_Test>
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book,
I get 2 groups of errors for 2 invalid XML elements:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
float_double_datatype_test.xsd float_double_datatype_test.xml
Error:
Line number: 15
Column number: 35
Message: cvc-datatype-valid.1.2.1: '-1.23e1.23' is not a valid
value for 'float'. (Exponential part must an "integer")
Error:
Line number: 15
Column number: 35
Message: cvc-type.3.1.3: The value ' -1.23e1.23 ' of element
'Float' is not valid.
Error:
Line number: 25
Column number: 31
Message: cvc-datatype-valid.1.2.1: '+INF' is not a valid value for
'double'. ("+" sign is not allowed on "INF")
Error:
Line number: 25
Column number: 31
Message: cvc-type.3.1.3: The value ' +INF ' of element
'Double' is not valid.
Failed with errors: 4