From 60303b6324ac4211d7c4efad11e3f98269e2702e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 14 Mar 2013 08:59:35 -0400 Subject: better costBetween; avoid unnecessary fractional values --- Config/Cost.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Config') 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. -} -- cgit v1.2.3