Anti-Harassment Tools/SecurePoll Improvements/Test Results/Precision

Background
There are various calculations that get done when tallying an STV election. All of these could be affected by arithmetic precision bugs.

Due to the limited precision of any computer arithmetic, we cannot guarantee our results will always be precise. I have been trying to test the sort of precision errors we can possibly expect, and whether they are acceptable.

Caveat: I am not a numerical analyst, so I am not an expert in doing this sort of analysis.

Calculations/possible sources of numerical error (not exhaustive):
 * Droop quota
 * Keep factors for each candidate
 * Vote distribution
 * Surplus
 * Total votes

See "Issue 3" in T289347#7301407.

Vote distribution
In STV, each vote is divided up and given to candidates based on a formula. For example, if a vote lists preferences as if Candidate A has reached the quota and been elected then they would only receive a proportion x of the vote and Candidate B would receive the remainder (1 - x). If Candidate B also reached the quota they would receive a proportion of the remainder ((1 - x) * y) and Candidate C would receive the remainder ((1 - x) * (1 - y)).
 * 1) Candidate A
 * 2) Candidate B
 * 3) Candidate C

Forward error analysis
I compared the vote distribution computed by SecurePoll with the "expected" vote distribution (calculated using bc, an arbitrary precision calculator).

There were at least two factors to consider: a few elections were generated to cover some of these factors.
 * 1) the number of candidates a single vote is divided between
 * 2) the number of proportional votes a candidate receives (particularly if those proportions are small)

Internal consistency
In each round we calculate each candidates previous rounds votes, votes earned in that round and total votes.

The precision of votes earned that round and total votes is not always the same. For example, even though in this round the votes earned is greater than 0, the difference between the previous rounds votes and total votes is 0.

By subtracting the previous rounds votes from the total votes and comparing to the votes earned that round, this give us a particular measure of precision (exactly the significance of this measure, I don't know).

Based on the large amounts of test data I had locally, the biggest difference I found was 1.35173650051E-10 (this result from this election).

Order of operands
A candidate's vote distribution is calculated like:

The order the operands appear in the calculation can affect the precision of the answer.

For example, to 16 decimal places in PHP:

The order of operands can vary from candidate to candidate.

For example, in this election, candidates 1 and 3 have slightly different "earned" votes in round 3 (see here), even though this number should be a the same (both candidates have exactly the same number of votes, including 2nd preferences). I suspect (although I cannot know for sure) that this is due to different orders of operands. The difference does not impact the candidates "total" votes, nor the election outcome.

I don't know if we can predict the effect, nor algorithmically decide which order of operands will give the "best" results.

Misc
The total votes are also calculated at the same time, which could affect the droop quota.