Recent threads on wikitech-l have pointed out that non-integer arithmetic done via the #expr parser function sometimes produces results unexpected by end users, due to the mismatch between the binary floating point used internally and the decimal input/output that the end-users work with.
While it's tempting to just tell people "that's how computers work, deal with it", that's a bit silly. :) PHP provides a standard module for arbitrary-precision decimal math ('bc').
Setting some decently large but not huge precision and using this for #expr math when the extension is available would probably provide more consistent results, and performance would not be significantly affected since this is a tiny portion of text processing time.
One thing to note however is that results would still be inconsistent between installs with BC available and those without, so third-party installs might not get the template results they want.
Some examples of "surprises" from the thread:
- {{#expr:floor(0.00007*100000)}} = 6 (expect 7)
- {{#expr:0.07*100 = 7}} is 0/False (expect 1/True)
- {{#expr:5/6 = (1/6)*5}} is 0/False (expect 1/True... but this might still not work with fixed-precision math automatically; that needs a fuzzy delta in the comparison)
Version: unspecified
Severity: enhancement
URL: http://www.php.net/bc