promote doubles to decimals

Elliotte:
You are correct in that if decimal is defined to have an unlimited
number of digits
then the value space for decimal is larger than that of IEEE 754 float
or double.
However, few languages support decimals with an unlimited number of
digits and none
do it efficiently.

For this reason, XML Schema added an implementation note that said the
conforming 
implementations must support decimal numbers with up to 18 decimal
digits.  They can
support more digits if they want to.  The restriction of 18 digits was
arrived at
as the maximum numbers of digits that could be supported by a 64 bit
binary implementation.
With this restriction, the value space of decimal is smaller than the
value space for
IEEE float which is smaller than the value space for IEEE double.

XML Schema does not, however, say what a processor that supports 18
digits is presented
with a number that has, say, 19 digits.  There are three possible
answers: error, round
or truncate.  Rounding is preferable to truncation and we are currently
debating between
error or rounding. 

-----Original Message-----
From: Elliotte Rusty Harold [mailto:elharo@metalab.unc.edu] 
Sent: Thursday, March 21, 2002 8:47 AM
To: www-xml-query-comments@w3.org
Subject: promote doubles to decimals

Section 3.3 of the functions and operators draft states:

|decimal| may be promoted to |float|, and |float| may be promoted to
|double|.

This strikes me as backwards. decimal is a broader type than double. For

instance, there is no maximum size for a decimal, whereas there is a 
maximum size for a double. double and float should be promoted to 
decimal when necessary, not decimal to float.

The schema data types spec requires implementations to support at least 
18 decimal digits for decimals. I need to work out the math, but off the

top of my head and with a quick Google search which turned up 
http://lists.w3.org/Archives/Public/www-xml-schema-comments/2000JulSep/0
187.html 
I think that even a double only gives you about 14 decimal digits of 
precision.


-- 
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible, 2nd Edition (IDG Books, 2001)                       |
| http://www.cafeconleche.org/books/bible2/                          |
| http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/     |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/        |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/     |
+----------------------------------+---------------------------------+




All the best, Ashok 
===========================================================
Ashok Malhotra              <mailto: ashokma@microsoft.com> 
Microsoft Corporation
212 Hessian Hills Road
Croton-On-Hudson, NY 10520 USA 
Redmond: 425-703-9462                New York: 914-271-6477 

Received on Monday, 25 March 2002 18:33:32 UTC