Re: Discussion of op:same-key

> 
> 1 div 3 cast as xs:float has string value 0.33333334 and precise decimal value 0.33333 33432 67440 79589 84375.

I was a little surprised by this: since the mantissa/significand of an xs:float value is less than 2^24 (16777216), why should the precise decimal value of an xs:float occupy 25 digits?

The answer is of course that although there are only 16777216 possible values of the mantissa, these values are thinly spread out among the space of xs:decimal values.

One observation I would make is that although the spec describes an algorithm whereby numbers are expressed as exact decimal values, that doesn't prescribe an implementation. I can imagine algorithms that compare an xs:float and an xs:decimal for "precise equality" without converting the xs:float to an arbitrary-precision decimal.

Furthermore, even if the comparison is done by converting to an arbitrary precision decimal representation, this doesn't necessarily require use of a library with support for arithmetic on arbitrary precision decimals. The only operations that the arbitrary-precision decimal representation needs to support are conversion from float, double, and decimal, and equality comparison.

Michael Kay
Saxonica

Received on Thursday, 2 June 2016 11:13:03 UTC