From c3905924154d9a8d56bdc57e2f36fe48b8524eef Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 4 Feb 2013 22:17:11 -0500 Subject: [PATCH] Replace (fromRational . toRational) with realToFrac everywhere. --- src/Integration/Simpson.hs | 2 +- src/Integration/Trapezoid.hs | 2 +- src/Normed.hs | 16 ++++++++-------- src/ODE/IVP.hs | 2 +- src/Vector.hs | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Integration/Simpson.hs b/src/Integration/Simpson.hs index b700022..2481f85 100644 --- a/src/Integration/Simpson.hs +++ b/src/Integration/Simpson.hs @@ -38,7 +38,7 @@ simpson_1 :: (RealFrac a, Fractional b, Num b) simpson_1 f a b = coefficient * ((f a) + 4*(f midpoint) + (f b)) where - coefficient = (fromRational $ toRational (b - a)) / 6 + coefficient = (realToFrac (b - a)) / 6 midpoint = (a + b) / 2 diff --git a/src/Integration/Trapezoid.hs b/src/Integration/Trapezoid.hs index 8d4b769..5452a5e 100644 --- a/src/Integration/Trapezoid.hs +++ b/src/Integration/Trapezoid.hs @@ -30,7 +30,7 @@ trapezoid_1 :: (RealFrac a, Fractional b, Num b) -> a -- ^ The \"right\" endpoint, @b@ -> b trapezoid_1 f a b = - (((f a) + (f b)) / 2) * (fromRational $ toRational (b - a)) + (((f a) + (f b)) / 2) * (realToFrac (b - a)) -- | Use the composite trapezoid rule to numerically integrate @f@ diff --git a/src/Normed.hs b/src/Normed.hs index 0187df9..9bef763 100644 --- a/src/Normed.hs +++ b/src/Normed.hs @@ -25,17 +25,17 @@ instance Normed Integer where norm_infty = fromInteger instance Normed Rational where - norm_p _ = fromRational - norm_infty = fromRational + norm_p _ = realToFrac + norm_infty = realToFrac instance Epsilon e => Normed (BigFloat e) where - norm_p _ = fromRational . toRational - norm_infty = fromRational . toRational + norm_p _ = realToFrac + norm_infty = realToFrac instance Normed Float where - norm_p _ = fromRational . toRational - norm_infty = fromRational . toRational + norm_p _ = realToFrac + norm_infty = realToFrac instance Normed Double where - norm_p _ = fromRational . toRational - norm_infty = fromRational . toRational + norm_p _ = realToFrac + norm_infty = realToFrac diff --git a/src/ODE/IVP.hs b/src/ODE/IVP.hs index d4876de..6bde763 100644 --- a/src/ODE/IVP.hs +++ b/src/ODE/IVP.hs @@ -35,7 +35,7 @@ eulers_method1 :: (RealFrac a, RealFrac b) eulers_method1 x0 y0 f h = y0 + h'*y' where - h' = fromRational $ toRational h + h' = realToFrac h y' = (f x0 y0) diff --git a/src/Vector.hs b/src/Vector.hs index f55808b..a4d3c13 100644 --- a/src/Vector.hs +++ b/src/Vector.hs @@ -143,7 +143,7 @@ instance (RealFloat a, Ord a, Vector v a) => Normed (Vn v a) where -- >>> norm_infty v1 -- 5 -- - norm_infty (Vn v1) = fromRational $ toRational $ V.foldl max 0 v1 + norm_infty (Vn v1) = realToFrac $ V.foldl max 0 v1 -- | Generic p-norms. The usual norm in R^n is (norm_p 2). -- @@ -156,7 +156,7 @@ instance (RealFloat a, Ord a, Vector v a) => Normed (Vn v a) where -- 5.0 -- norm_p p (Vn v1) = - fromRational $ toRational $ root $ V.sum $ V.map (exponentiate . abs) v1 + realToFrac $ root $ V.sum $ V.map (exponentiate . abs) v1 where exponentiate = (** (fromIntegral p)) root = (** (recip (fromIntegral p))) -- 2.44.2