From: Francis Russell Date: Fri, 12 Apr 2013 16:10:17 +0000 (+0100) Subject: Fix raising rationals to negative integers. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=0251b0b84648864af5e9b82c58eef093aa647945;p=francis%2Flta.git Fix raising rationals to negative integers. Haskell's Ratio implementation complains about negative exponents. --- diff --git a/LTA/Symbolic.hs b/LTA/Symbolic.hs index 3472fcb..c0e04d0 100644 --- a/LTA/Symbolic.hs +++ b/LTA/Symbolic.hs @@ -10,7 +10,7 @@ module LTA.Symbolic ) where import Control.Applicative ((<$>)) -import Data.Ratio (numerator, denominator, (%)) +import Data.Ratio (numerator, denominator) import Data.List (foldl') import Data.Map (Map) import qualified Data.Map as Map @@ -150,7 +150,9 @@ evalPow (Literal a) (Literal b) = evalPow' a b where evalPow' (FloatLiteral x) (FloatLiteral y) = Just . FloatLiteral $ x ** y evalPow' (RationalLiteral x) (RationalLiteral y) = if (denominator y) == 1 then let power = numerator y in - Just . RationalLiteral $ (numerator x ^ power) % (denominator x ^ power) + Just . RationalLiteral $ if power >= 0 + then x ^ power + else (recip x) ^ (- power) else Nothing evalPow' _ _ = Nothing evalPow _ _ = Nothing