Stream: fhirpath
Topic: Fixed-precision decimal
Paul Lynch (Sep 24 2018 at 17:49):
I see the spec says, "implementations should use fixed-precision decimal formats". Does that refer to keeping the same number of digits after the decimal point for all numbers? (I am used to "precision" meaning "number of significant digits", which can include digits the left of the decimal.)
Richard Townley-O'Neill (Sep 25 2018 at 01:46):
I think that the point is to preserve significant digits, so 2.10 must not be changed to 2.1.
Paul Lynch (Sep 25 2018 at 14:07):
While I agree with you that 2.10 means something more precise than 2.1, the FHIRPath spec (6.1.2, Equivalent) says that for decimals, "comparison is done on values rounded to the precision of the least precise operand. Trailing zeroes are ignored in determining precision." That last sentence would mean that 2.10 ~ 2.11. I am not sure if that was the intent.
Grahame Grieve (Sep 26 2018 at 08:06):
I'm not sure about the sentence - sounds like an error to me
Paul Lynch (Sep 26 2018 at 14:24):
I suspect it might have just been a compromise to keep things from getting too complex. If you do not ignore trailing zeros, then you have to keep track of the "scale" (digits the right of the decimal), and internally the Decimal type becomes a structure to carry that information around. Once you do that you open up questions of what happens when (for example) two Decimals are multiplied-- does the scale get reduced, and by how much? These questions would be answerable if we converted all numbers to scientific notation and used the concept of significant digits, but then FHIRPath would have to answer the question of how to convert an input of say, "20" into scientific notation -- would "20" mean two significant digits or just one? So, I can see why FHIRPath does not use significant digits.
Last updated: Apr 12 2022 at 19:14 UTC