Fixed -- bug and incorrect display
This commit is contained in:
parent
e38576c1d8
commit
6cada53cb0
2 changed files with 3 additions and 2 deletions
|
@ -18,8 +18,8 @@ precision = 5 :: Int
|
||||||
showRatio :: Int -> Rational -> String
|
showRatio :: Int -> Rational -> String
|
||||||
showRatio p r = (if (r < 0) then "-" else "") ++ prepoint_digits ++ "." ++ postpoint_digits
|
showRatio p r = (if (r < 0) then "-" else "") ++ prepoint_digits ++ "." ++ postpoint_digits
|
||||||
where
|
where
|
||||||
prepoint_digits = init . show . round $ (r * 10)
|
prepoint_digits = init . show . round . abs $ (r * 10)
|
||||||
postpoint_digits = (take p) . (drop (length prepoint_digits)) . show . round $ (r * 10^p)
|
postpoint_digits = (take p) . (drop (length prepoint_digits)) . show . round . abs $ (r * 10^p)
|
||||||
|
|
||||||
useResult (Right e) = (showRatio precision) . evaluate $ replaceVars e vars
|
useResult (Right e) = (showRatio precision) . evaluate $ replaceVars e vars
|
||||||
useResult (Left e) = show e
|
useResult (Left e) = show e
|
||||||
|
|
|
@ -85,6 +85,7 @@ rationalPower :: Rational -> Rational -> Rational
|
||||||
rationalPower a b = rationalPower' (numerator a, denominator a) (numerator b, denominator b)
|
rationalPower a b = rationalPower' (numerator a, denominator a) (numerator b, denominator b)
|
||||||
where
|
where
|
||||||
rationalPower' (a, b) (c, 1) = a ^ c % b ^ c
|
rationalPower' (a, b) (c, 1) = a ^ c % b ^ c
|
||||||
|
rationalPower' _ _ = error "Powers with unnatural numbers are not supported yet"
|
||||||
|
|
||||||
term = m_parens exprparser
|
term = m_parens exprparser
|
||||||
<|> fmap Variable m_identifier
|
<|> fmap Variable m_identifier
|
||||||
|
|
Loading…
Reference in a new issue