apportionment- Round a set of numbers while maintaining its sum

Safe HaskellSafe




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.

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 #

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.