Reputation: 494
Using numeric variables, what is the best practice to encode results of measurements that are below or above the range provided by the instrumentation (e.g. TSH < 0.001)? In the specific case this is needed for a medical project, but the problem is expected to apply to any kind of measurement. In my own research I couldn’t find a satisfactory solution up to now.
Generally, this class of problems is addressed in medical data formats, e.g. HL7, but there, numeric values are basically represented as strings. Is there an efficient way to do this with numeric data types (apart from a separate flag variable indicating if the result is within, below or above the cut-off value of the range of measurement)?
This should preferably be a cross-platform solution independent of the used processor architecture and being compatible with Pascal or Object Pascal, but elegant solutions in other programming languages are welcome, too.
Upvotes: 1
Views: 88
Reputation: 43033
The double
values, in their IEEE definition, have already some "special values".
0 11111111111 00000000000000000000000000000000000000000000000000002 ≙ 7FF0 0000 0000 000016
≙ +∞ (positive infinity)
1 11111111111 00000000000000000000000000000000000000000000000000002 ≙ FFF0 0000 0000 000016
≙ −∞ (negative infinity)
You may reuse these "flags" for below/above range values.
Every language can recognize those values, e.g. Delphi/FPC Math.pas
unit defines NegInfinity
and Infinity
if I remember correctly:
Infinity = 1.0 / 0.0;
NegInfinity = -1.0 / 0.0;
One side advantage is that they will be converted as text properly as non numbers (+INF/-INF
), so it may help debugging and tracing those values.
Of course, you should detect and avoid computing with those values (e.g. a mean/R² or curve fitting), which may break your calculation with the correct values. But the result will probably be so obviously wrong (infinity will preempt other values in most mathematical operations) that it could be not too difficult to track this problem.
Check this article as reference.
Upvotes: 1