cqframework / cql-engine

Clinical Quality Language Evaluation Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decimal literal magnitude and precision not constrained to CQL spec limits

duncand opened this issue · comments

Currently one can select Decimal values via Decimal literals with any precision, despite the CQL section 3.4.1 System-Defined Types saying the type's step size is 10^-8.

Run the following:

define DecimalTenStep:   0.0000001
define DecimalOneStep:   0.00000001
define DecimalTenthStep: 0.000000001

Its actual result:

>> DecimalTenStep [1:1] 1E-7
>> DecimalOneStep [2:1] 1E-8
>> DecimalTenthStep [3:1] 1E-9

What we expect is that DecimalTenthStep would either produce an error citing a literal using more precision than the step size, or else DecimalTenthStep would evaluate to the nearest value by rounding that is an even multiple of the step size.

Similarly, one can currently select Decimal values via Decimal literals with any magnitude, despite the same section of the CQL spec saying the type's range is -10^28 – 10^-8..10^28 – 10^-8.

All 4 of the following CQL statements will evaluate and produce results, but we expect only the first two would succeed and the second two would raise an error of having too great a magnitude.

define x1:  9999999999999999999999999999.99999999
define x2: -9999999999999999999999999999.99999999
define y1: 10000000000000000000000000000.00000000
define y2:-10000000000000000000000000000.00000000

These constraint and/or rounding errors raised in this comment plus the initial issue are reflected in these failing test suite tests:

  • ValueLiteralsAndSelectors.xml -> Decimal -> DecimalTenthStep
  • ValueLiteralsAndSelectors.xml -> Decimal -> DecimalPosTenthStep
  • ValueLiteralsAndSelectors.xml -> Decimal -> DecimalNegTenthStep
  • ValueLiteralsAndSelectors.xml -> Decimal -> Decimal10Pow28
  • ValueLiteralsAndSelectors.xml -> Decimal -> DecimalPos10Pow28
  • ValueLiteralsAndSelectors.xml -> Decimal -> DecimalNeg10Pow28

For precision-based values, the sizes specified in the CQL specification are floors, not ceilings. So long as they behave consistently and correctly according to the operation semantics when dealing with precision, implementations are free to use greater precision than required by the specification.