apportionment-0.0.0.2: Round a set of numbers while maintaining its sum

Math.Apportionment

Synopsis

# Documentation

largestRemainder :: RealFrac a => [a] -> [Int] Source

This function rounds values such that the sum of the rounded values matches the rounded sum of the original values.

Also known as Hare-Niemeyer method. https://en.wikipedia.org/wiki/Largest_remainder_method

Input values must be non-negative, otherwise `properFraction` bites us.

largestRemainderScaled :: RealFrac a => Int -> [a] -> [Int] Source

`largestRemainderScaled s xs` scales and rounds the values in `xs` such that their sum becomes `s`.

E.g. `largestRemainderScaled 100 [1,2,3]` returns integral percentages proportional to 1:2:3.

highestAveragesScaled :: RealFrac a => [a] -> Int -> [a] -> [Int] Source

https://en.wikipedia.org/wiki/Highest_averages_method

In `highestAveragesScaled divs s xs`, `divs` must be an infinite list of strictly increasing positive numbers. E.g. `highestAveragesScaled dHondtDivisors s xs` runs the d'Hondt method.