Copyright © 2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This document defines a datatype designed for compatibility with IEEE 754 floating-point decimal data, which can be supported by XSD 1.1 processors as an implementation-defined datatype.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document is a W3C Working Group Note as described in the World Wide Web Consortium Process Document. It contains a definition of a precisionDecimal datatype designed for compatibility with IEEE 754 floating-point decimal numbers.
In its current state, this document contains all the material specific to the precisionDecimal datatype that has appeared in working drafts of [XSD 1.1 Part 2: Datatypes], including some revisions made since the most recent public working draft. It is substantially complete as a specification of the datatype, though some further changes (listed in To-do list (non-normative) (§D)) may be made in a future revision of this document.
Comments on this document should be sent to the W3C XML Schema comments mailing list, [email protected] (archive). Each email message should contain only one comment.
Publication as a Working Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document has been produced by the W3C XML Schema Working Group as part of the W3C XML Activity. The authors of this document are the members of the XML Schema Working Group.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
A Normative references
B Non-normative references
C Acknowledgements (non-normative)
D To-do list (non-normative)
This document defines an XSD datatype intended to support the floating-point decimal defined by IEEE 754.
IEEE 754 defines both floating-point binary and floating-point decimal formats. The binary formats have been widely adopted since their initial introduction; if the floating-point decimal formats are also widely adopted for applications, it will be convenient to be able to represent values of that type in XML documents or in other contexts where XSD datatypes are used.
The following terms are used in this specification with the meanings indicated.
Except as specified below, in this specification terms defined in [XSD 1.1 Part 2: Datatypes] have the meanings given there.
[Definition:] The precisionDecimal datatype represents decimal numbers which retain precision; it also includes values for positive and negative infinity and for "not a number", and it differentiates between "positive zero" and "negative zero". This datatype is introduced to provide a variant of decimal from which may be derived datatypes closely corresponding to the floating-point decimal datatypes described by [IEEE 754-2008].
The
datatype precisionDecimal draws its name from a
common usage of the term 'precision' to mean the
degree of accuracy with which a quantity is recorded. In this
usage, writing a number as '2
' or as
'2.00
' is taken as recording the value with less or
more precision.
NaN
' is the lexical
representation of the precisionDecimal value whose ·numericalValue· property has the special value
notANumber. Accordingly, in English text we
use 'NaN' to refer to that value.
Similarly we use 'INF' and
'−INF' to refer to the two values
whose ·numericalValue· properties have the
special values positiveInfinity and
negativeInfinity. These three precisionDecimal values
are also informally called "not-a-number",
"positive infinity", and "negative
infinity". The latter two together are called
"the infinities".INF
', '+INF
',
'-INF
', and 'NaN
'.
(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)([Ee](\+|-)?[0-9]+)?
|(\+|-)?INF|NaN
The lexical mapping for precisionDecimal is ·precisionDecimalLexicalMap·. The canonical mapping is ·precisionDecimalCanonicalMap·.
3
' ( 3 , 0 ,
positive ) '3
'3.00
' ( 3 , 2 ,
positive ) '3.00
'03.00
' ( 3 , 2 ,
positive ) '3.00
'300
' ( 300 , 0 ,
positive ) '300
'3.00e2
' ( 300 , 0 ,
positive ) '300
'3.0e2
' ( 300 , −1 ,
positive ) '3.0E2
'30e1
' ( 300 , −1 ,
positive ) '3.0E2
'.30e3
' ( 300 , −1 ,
positive ) '3.0E2
'INF
'
and 'NaN
', as well as those of
'INFINITY
'; in many cases it permits language
definitions to prescribe which variants are used. This
specification explicitly chooses only 'INF
'
and 'NaN
'. 754 also permits language
definitions to prescribe whether '+
' shall be
used with positive values; this specification makes the
'+
' optional.0.1
' maps, in double, to
0.1000000000000000055511151231257827021181583404541015625.
If the , ·minScale·, and ·maxScale·
facets were available for double (they are not) and were
used to define the float type (again, they are not), the
value just mentioned would be dropped, and the literal
'0.1
' would be dropped along with it,
instead of mapping (as in fact it does) to the value
0.100000001490116119384765625.The precisionDecimal datatype and all datatypes derived from it by restriction have the following ·constraining facets· with fixed values; these facets must not be changed from the values shown:
Datatypes derived by restriction from precisionDecimal may also specify values for the following ·constraining facets·:
The precisionDecimal datatype has the following values for its ·fundamental facets·:
The assertions, enumeration, maxInclusive, maxExclusive, minExclusive, minInclusive, and pattern facets defined by [XSD 1.1 Part 2: Datatypes] can be used in deriving new types from precisionDecimal by restriction; their meaning and use are as documented in [XSD 1.1 Part 2: Datatypes].
The totalDigits facet defined by [XSD 1.1 Part 2: Datatypes] can also be used. Its meaning, when applied to values of type precisionDecimal, is described in totalDigits (§4.1). Except as otherwise specified in totalDigits (§4.1), all the constraints on the use of the totalDigits facet described in [XSD 1.1 Part 2: Datatypes] continue to apply when the facet is used with precisionDecimal values.
In addition, two facets not defined by [XSD 1.1 Part 2: Datatypes] can be used when restricting precisionDecimal. They are described in maxScale (§4.2) and minScale (§4.3).
For precisionDecimal values with ·numericalValue· of nV and ·scale· of aP, if the value of is t, the effect of the facet is to require that (aP + 1 + log10(| nV |) div 1) ≤ t, for values other than zero, NaN, and the infinities. This means in effect that values are expressible in scientific notation using at most t digits for the coefficient.
[Definition:] maxScale places an upper limit on the ·scale· of precisionDecimal values: if the {value} of maxScale = m, then only values with ·scale· ≤ m are retained in the value space. As a consequence, every value in the value space will have ·numericalValue· equal to i / 10n for some integers i and n, with n ≤ m. The {value} of maxScale must be an integer. If it is negative, the numeric values of the datatype are restricted to multiples of 10 (or 100, or …).
The term 'maxScale' is chosen to reflect the fact that it restricts the value space to those values that can be represented lexically in scientific notation using an integer coefficient and a scale (or negative exponent) no greater than maxScale. (It has nothing to do with the use of the term 'scale' to denote the radix or base of a notation.) Note that maxScale does not restrict the lexical space directly; a lexical representation that adds non-significant leading or trailing zero digits, or that uses a lower exponent with a non-integer coefficient is still permitted.
<simpleType name='decimal32'> <restriction base='precisionDecimal'> <totalDigits value='7'/> <maxScale value='95'/> <minScale value='-96'/> </restriction> </simpleType>
If {fixed} is true, then types for which the current type is the {base type definition} must not specify a value for maxScale other than {value}.
The XML representation for a maxScale schema component is a <maxScale> element information item. The correspondences between the properties of the information item and properties of the component are as follows:
maxScale
Element Information Item[Definition:] minScale places a lower limit on the ·scale· of precisionDecimal values. If the {value} of minScale is m, then the value space is restricted to values with ·scale· ≥ m. As a consequence, every value in the value space will have ·numericalValue· equal to i / 10n for some integers i and n, with n ≥ m.
The term minScale is chosen to reflect the fact that it restricts the value space to those values that can be represented lexically in exponential form using an integer coefficient and a scale (negative exponent) at least as large as minScale. Note that it does not restrict the lexical space directly; a lexical representation that adds additional leading zero digits, or that uses a larger exponent (and a correspondingly smaller coefficient) is still permitted.
DECIMAL(8,2)
. The effect is to allow values
between -999,999.99 and 999,999.99, with a fixed interval
of 0.01 between values.
<simpleType name='price'> <restriction base='precisionDecimal'> <totalDigits value='8'/> <minScale value='2'/> <maxScale value='2'/> </restriction> </simpleType>
If {fixed} is true, then types for which the current type is the {base type definition} must not specify a value for minScale other than {value}.
The XML representation for a minScale schema component is a <minScale> element information item. The correspondences between the properties of the information item and properties of the component are as follows:
minScale
Element Information ItemNote that it is not an error for minScale to be greater than .
All minimally conforming processors must support all precisionDecimal values in the value space of the otherwise unconstrained derived datatype for which is set to sixteen, maxScale to 369, and minScale to −398.
[XPath 2.0] does not currently require support for the precisionDecimal datatype, but conforming XPath processors are allowed to support additional primitive data types, including precisionDecimal.
For interoperability, it is recommended that XPath processors
intending to support precisionDecimal as an additional
primitive data type follow the recommendations in [Chamberlin 2006]. If the XPath processor used to
evaluate XPath expressions supports precisionDecimal, then any
precisionDecimal values in the post-schema-validation infoset should be labeled as
xs:precisionDecimal
in the data model instance
and handled accordingly in XPath.
If the XPath processor does not support precisionDecimal, then any precisionDecimal values in the post-schema-validation infoset should be mapped into decimal, unless the ·numericalValue· is not a decimal number (for example, it is positiveInfinity, negativeInfinity, or notANumber), in which case they should be mapped to float. Whether this is done by altering the type information in the partial post-schema-validation infoset, or by altering the usual rules for mapping from a post-schema-validation infoset to an [XDM] data model instance, or by treating precisionDecimal as an unknown type which is coerced as appropriate into decimal or float by the XPath processor, is implementation-defined and out of scope for this specification.
As a consequence of the above variability, it is possible that XPath expressions that perform various kinds of type introspections will produce different results when different XPath processors are used. If the schema author wishes to ensure interoperable results, such introspections will need to be avoided.
The functions defined below make frequent reference to functions defined in [XSD 1.1 Part 2: Datatypes].
LEX | : | matches decimalPtNumeral |
.
') and may optionally contain a
following fracFrag
F consisting of some number n of
digits.
LEX | : | matches scientificNotationNumeral |
E
' or
'e
', and a following noDecimalPtNumeral
E.LEX | : | matches pDecimalRep |
Let | pD be a complete precisionDecimal value. |
NaN
'-
', andpD | : | a precisionDecimal value |
0
'.0
',
preceded by a decimal point if and only if
m contains no decimal point and
aP + p − f is
greater than zero.E
' & n.
This document was prepared by the W3C XML Schema Working Group. The members at the time of publication were: