summaryrefslogtreecommitdiff
path: root/Config/Cost.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-14 08:59:35 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-14 08:59:35 -0400
commit60303b6324ac4211d7c4efad11e3f98269e2702e (patch)
treeffea81ba11eab34fffa001deab23b68f5f87fdea /Config/Cost.hs
parent4d53eac1bbe50eb2ce333baec7fd5e42d86e7373 (diff)
better costBetween; avoid unnecessary fractional values
Diffstat (limited to 'Config/Cost.hs')
-rw-r--r--Config/Cost.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/Config/Cost.hs b/Config/Cost.hs
index dd3968e78..94bab1fe1 100644
--- a/Config/Cost.hs
+++ b/Config/Cost.hs
@@ -33,8 +33,8 @@ encryptedRemoteCostAdj = 50
- the list, inserts a new cost into the list, in between the item
- and the item after it.
-
- - If both items have the same cost, one of them will have its cost
- - adjusted to make room. The costs of other items in the list are left
+ - If two or move items have the same cost, their costs are adjusted
+ - to make room. The costs of other items in the list are left
- unchanged.
-
- To insert the new cost before any other in the list, specify a negative
@@ -63,7 +63,10 @@ insertCostAfter l pos
costBetween :: Cost -> Cost -> Cost
costBetween x y
| x == y = x
- | x > y = y + (x - y) / 2
+ | x > y = -- avoid fractions unless needed
+ let mid = y + (x - y) / 2
+ mid' = fromIntegral ((floor mid) :: Int)
+ in if mid' > y then mid' else mid
| otherwise = costBetween y x
{- Make sure the remote cost numbers work out. -}