Page MenuHomePhabricator

Investigate whether BCmath is sufficient for Wikibase
Open, Needs TriagePublic

Description

The BCmath extension is a small extension to do a few mathematical operations on big numbers, using the BCMath PHP library for arbitrary precision mathematics. It seems sufficient, but it could be that something more complete or faster is necessary, like full compliance with the IEEE 754r standard, or in other words fixing the abandoned ldecnumber library. This is a much bigger libary (Lua Module Documentation).

Visual inspection seems to indicate the quantity type follows the assumptions used by BCmath, but no docs have been found that this is in fact the intended behavior. It could just be a coincidence.

The intention with BCmath is to be able to do unit conversions on big numbers, not to do heavy number crunching. Thus simplicity and safe operations are more of a concern than fast operation. That is the reason for using the BC library through the PHP interface, which are not especially fast. If speed is necessary, then ledecnumber should be fixed instead.

Event Timeline

jeblad created this task.Mon, Oct 7, 6:42 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMon, Oct 7, 6:42 AM
Peachey88 removed a subscriber: Wikidata.
Peachey88 added a subscriber: Peachey88.
Peachey88 removed a subscriber: Peachey88.

It seems sufficient, but it could be that something more complete or faster is necessary,

@jeblad: "sufficient" or "necessary" for what exactly? Is this a proposal to replace ldecnumber (if that is currently used by some Wikidata extension, not clear here?) with bcmath? This task is lacking any context; see https://www.mediawiki.org/wiki/How_to_report_a_bug

jeblad added a comment.EditedMon, Oct 7, 8:10 AM

The Wikibase number type uses bcmath, which is a PHP interface to the BC library, which is the library that implements the BC utility in *nix. The BCmath extension implements a Lua interface to the bcmath interface library in PHP. The bcmath C-library is pretty old, and is not IEEE 754 compliant, but the Wikibase numbers, ie the Wikibase quantity, ie a whole bunch of Wikidata statements use this format.

No, it is not a proposal to replace bcmath with decnumber, it is a question whether BCmath is a sufficient implementation according to the current assumptions made in Wikibase number.

I have already got a reply from people at WMDE, they use bcmath. The remaining question is whether the BCmath extension (aka Lua interface) is a sufficient implementation for processing Wikibase numbers according to their assumptions.

In particular https://github.com/wmde/Number/ and https://github.com/wmde/Number/blob/master/src/DataValues/DecimalMath.php