Statement. For every FeeRate r — natural numbers fee(r)≥0 and size(r) with the built-in condition size(r)>0 — and every natural number v,
getFee(r,v)=evaluateFeeUp((fee(r),size(r)),v),
where the left side, a natural number, is regarded as an integer, and on the right (fee(r),size(r)) is the FeeFrac whose fee and size are fee(r) and size(r) regarded as integers, and v is regarded as an integer.
Unfolded: the left side is (fee(r)v+size(r)−1)/size(r) (floor division of natural numbers). Since fee(r)≥0, the right side is
Binders and edge cases. There are no hypotheses beyond those built into the types: fee(r) and v are arbitrary natural numbers (including 0, and arbitrarily large — no word-size bounds), and size(r) is a positive natural number. Negative fees cannot occur on either side since the FeeRate fee is a natural number.
Definitions used, unfolded
Division conventions. Three kinds of division occur.
Default integer divisionn/d with remainder nmodd (Euclidean convention). For d>0: n/d=⌊n/d⌋ and nmodd=n−d⌊n/d⌋∈[0,d), also for negative n (e.g. −7/2=−4, −7mod2=1). For d<0: n/d=−⌊n/∣d∣⌋ and nmodd∈[0,∣d∣). For d=0: n/0=0 and nmod0=n.
Truncated divisiontdiv(n,d) with remainder tmod(n,d)=n−d⋅tdiv(n,d): the quotient is rounded toward zero, so the remainder is 0 or has the sign of n, with ∣tmod(n,d)∣<∣d∣ (e.g. tdiv(−7,2)=−3, tmod(−7,2)=−1). For d=0: tdiv(n,0)=0, tmod(n,0)=n.
Rational division in Q, with the convention q/0=0. For q∈Q, ⌊q⌋ is the greatest integer ≤q and ⌈q⌉ the least integer ≥q.
Below, [P] denotes 1 if the condition P holds and 0 otherwise.
FeeRate and getFee (from the imported replacement file). A FeeRater consists of natural numbers fee(r)≥0 and size(r) with the built-in requirement size(r)>0. For v∈N,
getFee(r,v)=(fee(r)⋅v+(size(r)−1))/size(r)
computed in the natural numbers with floor division (size(r)−1≥0 since size(r)>0).
FeeFrac. A FeeFrac is a pair X=(fee(X),size(X)) of two arbitrary integers. Nothing constrains them: either component may be zero or negative, and no machine-word bounds are imposed. Addition and subtraction are componentwise,
X±Y=(fee(X)±fee(Y),size(X)±size(Y)),
and the zero FeeFrac is (0,0). A chunk list is a finite list c=[c1,…,cn] of FeeFracs; the empty list (n=0) is allowed.
mul.mul(a,b)=a⋅b, the exact product of two integers.
div. For integers n,d and a boolean ρ ("round down"), with q=tdiv(n,d) and r=tmod(n,d) (truncated division):
div(n,d,ρ)=q+[r>0]−[r=0 and ρ].
Case by case: if r=0 the result is q; if r>0 it is q when ρ is true and q+1 when ρ is false; if r<0 it is q−1 when ρ is true and q when ρ is false. The definition places no condition on d: for d=0 it gives q=0, r=n, hence [n>0]−[n=0 and ρ]; for d<0 the remainder still carries the sign of n.
ceilDiv. For integers n,d, with default (Euclidean) integer division:
ceilDiv(n,d)=n/d+[nmodd=0].
The definition is stated for all integers (not only nonnegative ones); for d=0 it gives [n=0].
evaluateFee, evaluateFeeDown, evaluateFeeUp. For a FeeFrac X, an integer t ("at size") and a boolean ρ:
evaluateFee(X,t,ρ)=⎩⎨⎧(fee(X)⋅t)/size(X)ceilDiv(fee(X)⋅t,size(X))div(mul(fee(X),t),size(X),ρ)if 0≤fee(X)<233 and ρ is true,if 0≤fee(X)<233 and ρ is false,otherwise (fee(X)<0 or fee(X)≥233),
where 233=8589934592, the "/" in the first line is the default (Euclidean) integer division, and mul(a,b)=ab. Then evaluateFeeDown(X,t)=evaluateFee(X,t,true) and evaluateFeeUp(X,t)=evaluateFee(X,t,false). The definition itself imposes no condition on size(X) or t.
Confirmed by the moderator at approval.