[xquery-talk] Numeric type promotion
jsnelson at sleepycat.com
Thu Oct 19 14:30:24 PDT 2006
I'm having a hard time understanding the logic behind the XQuery
specification's numeric type promotion rules. There are three basic
numeric types decimal, float and double. The float and double types are
based on IEEE 754-1985 floating point numbers, and as such have certain
deficiencies - like upper and lower limits on their values, and problems
exactly representing common base 10 numbers.
The decimal type, on the other hand, is an arbitrary precision decimal
number, and can accurately represent any (base 10) number of any size.
Why then do the numeric type promotion rules specify that decimal is
converted to float or double, and not the other way around? XQuery users
are being forced to lower the precision of their numeric calculations by
performing type promotion this way around!
I'm sure that the extra state that is available in float and double came
into the decision - there is no way to represent Nan, INF, -INF or -0 in
decimal. However, mathematically -0 does not exist - it is an artifact
of the way that the numbers are stored, and the other three are really
only error states.
I'm sure the working group discussed these issues, I'm just wondering
why the decisions were made.
More information about the talk