# payroll.net-to-gross
Status: needs review by a qualified payroll professional before it is published.
Grossing up: the gross pay that gives an employee at least a target take-home
pay in one period, with everything else about them as for
`payroll.gross-to-net` (the `gross` in `input` is ignored).
## Why a search
Net pay has no clean inverse. Tax is charged on whole pounds, student loans
are rounded down to whole pounds, pension and National Insurance thresholds
switch on and off, and the income tax band a penny falls in depends on the
year to date. Algebra that inverts the rates works for the middle of a band
and is a penny or a pound out at every edge. So this runs `grossToNet` itself
and searches.
The search is a plain bisection on whole pence: start at 0 and at the target,
double the upper bound until its net reaches the target, then halve the gap
until it is one penny. Every step is integer arithmetic with fixed midpoints,
so the three languages take identical steps and return identical answers.
## What "the" answer is
The result is a gross `G` whose net is at least the target and where `G - 1p`
nets less than the target. Net pay does not only ever rise with gross: tax is
charged on whole pounds of taxable pay, so the penny that takes taxable pay
into the next pound adds 20p or more of tax and net pay dips; one more penny
can also cost a whole pound of student loan. Where the target sits clear of
those dips (the usual case, and every vector here) `G` is the smallest gross
that reaches it. Where it falls inside one, the bisection still returns a
penny-exact boundary, but a smaller gross elsewhere could also reach the
target, and the net may exceed the target by up to about £1. Check `net` on the
returned payslip rather than assuming it equals the target.
If a tax refund makes the net at zero gross already reach the target, the
payslip for zero gross is returned. The search refuses to look above
£10,000,000 for one period.
Sources: as `payroll.gross-to-net`.