RE: [F&O] 17.8 Two definitions for decimal -> double

The value space for float is, indeed, a subset of the value space for
double.  We spent a long time trying to specify how float 

could be derived from double and could find no facets that we could be
used to do this.  And even if we were able to find such

facets how could we then prevent people from deriving other nonsense
types from double that would be impossible to implement.

We talked a lot to the Java 2 folks when we did this in XML Schema and
they convinced us that float and double were really independent
primitive types whose value space happened to overlap.

 

The fact of the matter is that float and double are two specific binary
formats.  If you have a float in a 32 bit format there is no direct
method for converting it into a double in a 64 bit format and vice
versa.  This is the reason for the rule that goes via xs:string.  I'm
not crazy about this.  If you have better ideas, please write.

All the best, Ashok 

________________________________

From: Kay, Michael [mailto:Michael.Kay@softwareag.com] 
Sent: Thursday, October 09, 2003 9:42 AM
To: Ashok Malhotra; Sarah Wilkin; public-qt-comments@w3.org
Subject: RE: [F&O] 17.8 Two definitions for decimal -> double

 

> Sarah: 
> Thank you for your comment.  This has been fixed.  The 
> (single) rule now 
> reads: 
> 
> - If ST is xs:float or xs:decimal, or types derived from 
> them, then TV is xs:double(SV cast as xs:string) and the 
> conversion is complete. 
> 

Sarah also asked: 

Also, why would float need to be first cast to a string 
when double represents a superset of its values (both for the actual 
value as well as mantissa and exponent)? 

 

I have to say I am confused by this myself. I have also heard it
suggested that the reason xs:float is not defined in XML Schema as a
subtype of xs:double is that the value space of xs:float is not a subset
of the value space of xs:double.

 

The Java language spec says: 

The finite nonzero values of type float are of the form s.m.2^e, where s
is 
+1 or -1, m is a positive integer less than 2^24, and e is an integer
between -149 
and 104, inclusive. Values of that form such that m is positive but less
than 2^23 
and e is equal to -149 are said to be denormalized. 

The finite nonzero values of type double are of the form s.m.2^e, where
s is 
+1 or -1, m is a positive integer less than 2^53, and e is an integer
between -1075 
and 970, inclusive. Values of that form such that m is positive but less
than 2^52 
and e is equal to -1075 are said to be denormalized. 

These definitions certainly suggest that the value space of float is a
subspace of double. 

So why isn't float a subtype of double, and why do we convert from one
to the other via a string? 

Michael Kay 

Received on Thursday, 9 October 2003 13:15:28 UTC