From 6cada53cb0210b95a83ac9061b34a73b625fbc5a Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Sun, 15 Sep 2024 18:07:45 +0200 Subject: [PATCH] Fixed -- bug and incorrect display --- app/Main.hs | 4 ++-- src/Lib.hs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 054050c..5644a65 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -18,8 +18,8 @@ precision = 5 :: Int showRatio :: Int -> Rational -> String showRatio p r = (if (r < 0) then "-" else "") ++ prepoint_digits ++ "." ++ postpoint_digits where - prepoint_digits = init . show . round $ (r * 10) - postpoint_digits = (take p) . (drop (length prepoint_digits)) . show . round $ (r * 10^p) + prepoint_digits = init . show . round . abs $ (r * 10) + postpoint_digits = (take p) . (drop (length prepoint_digits)) . show . round . abs $ (r * 10^p) useResult (Right e) = (showRatio precision) . evaluate $ replaceVars e vars useResult (Left e) = show e diff --git a/src/Lib.hs b/src/Lib.hs index d83b50d..2b24d47 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -85,6 +85,7 @@ rationalPower :: Rational -> Rational -> Rational rationalPower a b = rationalPower' (numerator a, denominator a) (numerator b, denominator b) where rationalPower' (a, b) (c, 1) = a ^ c % b ^ c + rationalPower' _ _ = error "Powers with unnatural numbers are not supported yet" term = m_parens exprparser <|> fmap Variable m_identifier