Background
Here in the UK1, these are the income tax rules:
- You get a personal allowance (untaxed) of up to £12,570:
- If you earn less than £100,000, you get the full £12,570 as personal allowance
- For every £2 over £100,000, your personal allowance goes down by £1
- After the personal allowance, the next £37,700 is taxed at the "basic rate" of 20%
- After that, the next £99,730 is taxed at the "higher rate" of 40%
- Finally, anything above this is taxed at the "additional rate" of 45%
1: This isn't actually the case in Scotland; only England, Wales and Northern Ireland.
Your task
Using the above tax rules, take in an annual salary (as a positive integer) and calculate the income tax.
Test cases
Input Output
12570 0
50000 7486
80000 19432
120000 39432
200000 75588.5
Note: the final test case can be any of 75588, 75588.5, or 75589 (any is fine)
Clarifications
- You can choose whether to make the personal allowance an integer or keep it as a float
- e.g. if the input is £100,003, the personal allowance can be £12,569, £12,568.50, or £12,568
- The same goes for the final output. If it ends up as a float, you can make it an integer or keep it as a float
- (see the final test case)
- This is code-golf, so shortest answer in bytes wins!