Re: Discussion of op:same-key

On 02/06/2016 12:12, Michael Kay wrote:
>> 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.
Certainly there is the option of converting float/double to a 
round-tripping strings.  This isn't exactly a cheap operation, but at 
least the implementation is already required to do this.  Such behaviour 
might be clearer to the user - at least the user can see that the string 
representations would match.

>
> 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.
No, but it does require grubbing about inside the bits of a double. It's 
unlikely to be a fast operation - I note that the .NET framework passes 
off such unpleasantness to native code, presumably for performance reasons.

Cheers,
     Tim

Received on Thursday, 2 June 2016 12:06:53 UTC