From b3276132e360efea7f11fcfe378b85cba720a949 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Mon, 8 May 2023 00:12:01 -0400 Subject: [PATCH] ENH actually use percents --- lib/Internal/Insert.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Internal/Insert.hs b/lib/Internal/Insert.hs index 443ac5e..531edc1 100644 --- a/lib/Internal/Insert.hs +++ b/lib/Internal/Insert.hs @@ -327,7 +327,7 @@ allocatePre precision gross = L.mapAccumR go M.empty p = preValue faValue v = if prePercent faValue - then roundPrecision 3 p * gross + then (roundPrecision 3 p / 100) * gross else roundPrecision precision p in (mapAdd_ c v m, f {faValue = v}) @@ -359,7 +359,7 @@ allocateTax precision gross deds = fmap (fmap go) go TaxValue {tvCategories, tvMethod} = let agi = gross - sum (mapMaybe (`M.lookup` deds) tvCategories) in case tvMethod of - TMPercent p -> roundPrecision 3 p * agi + TMPercent p -> roundPrecision 3 p / 100 * agi TMBracket TaxProgression {tpDeductible, tpBrackets} -> foldBracket precision (agi - roundPrecision precision tpDeductible) tpBrackets @@ -371,14 +371,17 @@ allocatePost allocatePost precision aftertax = fmap (fmap go) where go PosttaxValue {postValue, postPercent} = - let v = postValue in if postPercent then aftertax * roundPrecision 3 v else roundPrecision precision v + let v = postValue + in if postPercent + then aftertax * roundPrecision 3 v / 100 + else roundPrecision precision v foldBracket :: Natural -> Rational -> [TaxBracket] -> Rational foldBracket precision agi bs = fst $ foldr go (0, agi) $ L.sortOn tbLowerLimit bs where go TaxBracket {tbLowerLimit, tbPercent} (acc, remain) = let l = roundPrecision precision tbLowerLimit - p = roundPrecision 3 tbPercent + p = roundPrecision 3 tbPercent / 100 in if remain < l then (acc + p * (remain - l), l) else (acc, remain) data FlatAllocation v = FlatAllocation