Last modified: 2013-11-20 13:47:09 UTC
Floating point errors should be avoided when handling/manipulating QueryValue and DecimalValue objects. One situation where such errors frequently show is when adding an uncertainty margin to a base amount to comput the upper and lower bounds of a quantity. The errors are introduced because DecimalMath, a class that implements basic arithmetical operation on DecimalValue objects, uses float numbers to perform the calculations. To avoid this, we could use the bcmath library, if it is installed. Also, smart rounding rules could be employed to reduce the ill effects of floating point errors.
Example: "raw": "3+/-0.01\u00b0", "value": { "amount": "+3", "unit": "\u00b0", "upperBound": "+3.0099999999999997868371792719699442386627197265625", "lowerBound": "+2.9900000000000002131628207280300557613372802734375" }, "type": "quantity"
Change 94355 had a related patch set uploaded by Daniel Kinzler: (bug 56682) DecimalMath now uses bcmath if available https://gerrit.wikimedia.org/r/94355
Change 94367 had a related patch set uploaded by Daniel Kinzler: (bug #56682) Use DecimalMath for getUncertaintyMargin https://gerrit.wikimedia.org/r/94367
Change 94355 merged by jenkins-bot: (bug 56682) DecimalMath now uses bcmath if available https://gerrit.wikimedia.org/r/94355
Change 94367 merged by jenkins-bot: (bug #56682) Use DecimalMath for getUncertaintyMargin. https://gerrit.wikimedia.org/r/94367
Verified in Wikidata demo time.