summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichalKonecny <>2017-11-14 16:22:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-11-14 16:22:00 (GMT)
commited2d49382e7a13521fa52d4ed9f67e9b9a72b1ad (patch)
tree10d81c9f50243de96704d2e0345594c3ffa3b96c
parent8f9dc561a2c32380fd146a28f1f08399926b178e (diff)
version 0.1.2.0HEAD0.1.2.0master
-rw-r--r--aern2-mp.cabal24
-rw-r--r--changelog.md2
-rw-r--r--src/AERN2/MP/UseMPFR/Float/Arithmetic.hs18
-rw-r--r--src/AERN2/MP/UseMPFR/Float/Conversions.hs18
-rw-r--r--src/AERN2/MP/UseMPFR/Float/RoundedAdaptor.hs52
-rw-r--r--src/AERN2/MP/UseMPFR/Float/Type.hs6
6 files changed, 68 insertions, 52 deletions
diff --git a/aern2-mp.cabal b/aern2-mp.cabal
index 4a560f4..0489744 100644
--- a/aern2-mp.cabal
+++ b/aern2-mp.cabal
@@ -1,5 +1,5 @@
name: aern2-mp
-version: 0.1.1.0
+version: 0.1.2.0
cabal-version: >= 1.9.2
build-type: Simple
homepage: https://github.com/michalkonecny/aern2
@@ -51,15 +51,15 @@ library
hs-source-dirs: src
build-depends:
base == 4.*
- , integer-logarithms >= 1.0 && < 1.1
- , convertible >= 1.1.1.0 && < 1.2
- , regex-tdfa >= 1.2.1 && < 1.3
- , hspec >= 2.1 && < 2.5
- -- , hspec-smallcheck >= 0.3 && < 0.5
- , QuickCheck >= 2.7 && < 2.10
- , lens >= 4.13 && < 4.16
+ , integer-logarithms
+ , convertible
+ , regex-tdfa
+ , hspec
+ -- , hspec-smallcheck >= 0.3
+ , QuickCheck
+ , lens
, template-haskell
- , mixed-types-num >= 0.3.1 && < 0.4
+ , mixed-types-num
if flag(MPFR)
cpp-options: -DUSEMPFR
if impl(ghc >= 7.10)
@@ -149,6 +149,6 @@ test-suite spec
base == 4.*
-- , mixed-types-num >= 0.3.1 && < 0.4
, aern2-mp
- , hspec >= 2.1 && < 2.5
- -- , hspec-smallcheck >= 0.3 && < 0.5
- , QuickCheck >= 2.7 && < 2.10
+ , hspec >= 2.1
+ -- , hspec-smallcheck >= 0.3
+ , QuickCheck >= 2.7
diff --git a/changelog.md b/changelog.md
index 17fbff8..5dcc5a6 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,5 @@
+* v 0.1.2.0 2017-11-14
+ * fix compilation with haskell-mpfr
* v 0.1.1.0 2017-11-14
* using Claude Heiland-Allen's Numeric.Rounded.Simple
* v 0.1.0.1 2017-09-12
diff --git a/src/AERN2/MP/UseMPFR/Float/Arithmetic.hs b/src/AERN2/MP/UseMPFR/Float/Arithmetic.hs
index 45bebda..10f351d 100644
--- a/src/AERN2/MP/UseMPFR/Float/Arithmetic.hs
+++ b/src/AERN2/MP/UseMPFR/Float/Arithmetic.hs
@@ -37,7 +37,7 @@ import AERN2.MP.UseMPFR.Float.Type
import qualified Data.Approximate.MPFRLowLevel as MPLow
one :: MPFloat
-one = MPLow.fromInt MPLow.TowardInf (P.fromInteger 10) (int 1)
+one = MPLow.fromInt MPLow.Up (P.fromInteger 10) (int 1)
#endif
@@ -93,11 +93,11 @@ recipDown x = divDown one x
piUp :: Precision -> MPFloat
piUp p =
- MPLow.pi MPLow.TowardInf (p2mpfrPrec p)
+ MPLow.pi MPLow.Up (p2mpfrPrec p)
piDown :: Precision -> MPFloat
piDown p =
- MPLow.pi MPLow.TowardNegInf (p2mpfrPrec p)
+ MPLow.pi MPLow.Down (p2mpfrPrec p)
cosUp :: MPFloat -> MPFloat
cosUp = unaryUp MPLow.cos
@@ -134,16 +134,16 @@ logDown = unaryDown MPLow.log
unaryUp ::
(MPLow.RoundMode -> MPLow.Precision -> MPFloat -> MPFloat) ->
(MPFloat -> MPFloat)
-unaryUp opRP x = opRP MPLow.TowardInf p x
+unaryUp opRP x = opRP MPLow.Up p x
where
- p = MPLow.precision x
+ p = MPLow.getPrec x
unaryDown ::
(MPLow.RoundMode -> MPLow.Precision -> MPFloat -> MPFloat) ->
(MPFloat -> MPFloat)
-unaryDown opRP x = opRP MPLow.TowardNegInf p x
+unaryDown opRP x = opRP MPLow.Down p x
where
- p = MPLow.precision x
+ p = MPLow.getPrec x
binaryUp ::
Bool ->
@@ -166,5 +166,5 @@ binaryApprox isUp _canBeExact opRP x y =
where
pMax = (getPrecision x) `max` (getPrecision y)
withPrec p
- | isUp = opRP MPLow.TowardInf (p2mpfrPrec p) x y
- | otherwise = opRP MPLow.TowardNegInf (p2mpfrPrec p) x y
+ | isUp = opRP MPLow.Up (p2mpfrPrec p) x y
+ | otherwise = opRP MPLow.Down (p2mpfrPrec p) x y
diff --git a/src/AERN2/MP/UseMPFR/Float/Conversions.hs b/src/AERN2/MP/UseMPFR/Float/Conversions.hs
index 8db685f..5b4499d 100644
--- a/src/AERN2/MP/UseMPFR/Float/Conversions.hs
+++ b/src/AERN2/MP/UseMPFR/Float/Conversions.hs
@@ -91,8 +91,8 @@ mpFromRationalA dir p q
where
(divDir, dirOpp) =
case dir of
- MPLow.TowardNegInf -> (divDown, MPLow.TowardInf)
- MPLow.TowardInf -> (divUp, MPLow.TowardNegInf)
+ MPLow.Down -> (divDown, MPLow.Up)
+ MPLow.Up -> (divUp, MPLow.Down)
_ -> error "in mpFromRationalA"
#endif
@@ -100,7 +100,7 @@ mpFromRationalA dir p q
instance HasNorm MPFloat where
getNormLog x
| x == 0 = NormZero
- | otherwise = NormBits (P.toInteger $ MPLow.exponent' x)
+ | otherwise = NormBits (P.toInteger $ MPLow.getExp x)
{- conversions -}
@@ -115,16 +115,16 @@ instance ConvertibleExactly MPFloat Rational where
safeConvertExactly = Right . mpToRational
toDoubleUp :: MPFloat -> Double
-toDoubleUp = mpToDouble MPLow.TowardInf
+toDoubleUp = mpToDouble MPLow.Up
toDoubleDown :: MPFloat -> Double
-toDoubleDown = mpToDouble MPLow.TowardNegInf
+toDoubleDown = mpToDouble MPLow.Down
fromIntegerUp :: Precision -> Integer -> MPFloat
-fromIntegerUp p i = MPLow.fromIntegerA MPLow.TowardInf (p2mpfrPrec p) i
+fromIntegerUp p i = MPLow.fromIntegerA MPLow.Up (p2mpfrPrec p) i
fromIntegerDown :: Precision -> Integer -> MPFloat
-fromIntegerDown p i = MPLow.fromIntegerA MPLow.TowardNegInf (p2mpfrPrec p) i
+fromIntegerDown p i = MPLow.fromIntegerA MPLow.Down (p2mpfrPrec p) i
type CanBeMPFloat t = ConvertibleExactly t MPFloat
mpFloat :: (CanBeMPFloat t) => t -> MPFloat
@@ -150,11 +150,11 @@ instance ConvertibleExactly Int MPFloat where
fromRationalUp :: Precision -> Rational -> MPFloat
fromRationalUp p x =
- mpFromRationalA MPLow.TowardInf (p2mpfrPrec p) x
+ mpFromRationalA MPLow.Up (p2mpfrPrec p) x
fromRationalDown :: Precision -> Rational -> MPFloat
fromRationalDown p x =
- mpFromRationalA MPLow.TowardNegInf (p2mpfrPrec p) x
+ mpFromRationalA MPLow.Down (p2mpfrPrec p) x
instance Convertible MPFloat Double where
safeConvert x
diff --git a/src/AERN2/MP/UseMPFR/Float/RoundedAdaptor.hs b/src/AERN2/MP/UseMPFR/Float/RoundedAdaptor.hs
index 74ee250..2e31882 100644
--- a/src/AERN2/MP/UseMPFR/Float/RoundedAdaptor.hs
+++ b/src/AERN2/MP/UseMPFR/Float/RoundedAdaptor.hs
@@ -32,45 +32,59 @@ import Numeric.Rounded.Simple
instance Show Rounded where
show = show'
-type RoundMode = RoundingMode
+getPrec :: Rounded -> Int
+getPrec = precision
+
+getExp :: Rounded -> Int
+getExp = exponent'
+
+data RoundMode = Up | Down
+
+withRoundMode :: (RoundingMode -> t) -> (RoundMode -> t)
+withRoundMode op Up = op TowardInf
+withRoundMode op Down = op TowardNegInf
+{-# INLINE withRoundMode #-}
+
+set :: RoundMode -> Precision -> Rounded -> Rounded
+set = withRoundMode precRound
defaultPrecision :: Precision
defaultPrecision = 10
pi :: RoundMode -> Precision -> Rounded
-pi = kPi
+pi = withRoundMode kPi
fromIntegerA :: RoundMode -> Precision -> Integer -> Rounded
-fromIntegerA = fromInteger'
+fromIntegerA = withRoundMode fromInteger'
zero, one :: Rounded
-zero = fromIntegerA TowardNearest defaultPrecision 0
-one = fromIntegerA TowardNearest defaultPrecision 1
+zero = fromIntegerA Up defaultPrecision 0
+one = fromIntegerA Up defaultPrecision 1
toDoubleA :: RoundMode -> Rounded -> Double
-toDoubleA = toDouble
+toDoubleA = withRoundMode toDouble
fromRationalA :: RoundMode -> Precision -> Rational -> Rounded
-fromRationalA = fromRational'
+fromRationalA = withRoundMode fromRational'
toRationalA :: Rounded -> Rational
toRationalA = toRational' TowardNearest
add, sub, mul, div, atan2 :: RoundMode -> Precision -> Rounded -> Rounded -> Rounded
-add = add_
-sub = sub_
-mul = mul_
-div = div_
-atan2 = atan2_
+add = withRoundMode add_
+sub = withRoundMode sub_
+mul = withRoundMode mul_
+div = withRoundMode div_
+atan2 = withRoundMode atan2_
neg, abs, sqrt, exp, log, sin, cos :: RoundMode -> Precision -> Rounded -> Rounded
-neg = negate_
-abs = abs_
-sqrt = sqrt_
-exp = exp_
-log = log_
-sin = sin_
-cos = cos_
+neg = withRoundMode negate_
+abs = withRoundMode abs_
+sqrt = withRoundMode sqrt_
+exp = withRoundMode exp_
+log = withRoundMode log_
+sin = withRoundMode sin_
+cos = withRoundMode cos_
-- TODO: add more ops
#endif
diff --git a/src/AERN2/MP/UseMPFR/Float/Type.hs b/src/AERN2/MP/UseMPFR/Float/Type.hs
index 8fd7b1e..884f235 100644
--- a/src/AERN2/MP/UseMPFR/Float/Type.hs
+++ b/src/AERN2/MP/UseMPFR/Float/Type.hs
@@ -79,13 +79,13 @@ p2mpfrPrec = P.fromInteger . integer
#endif
instance HasPrecision MPFloat where
- getPrecision x = prec (P.toInteger $ MPLow.precision x)
+ getPrecision x = prec (P.toInteger $ MPLow.getPrec x)
instance CanSetPrecision MPFloat where
setPrecision = setPrecisionUp
setPrecisionUp :: Precision -> MPFloat -> MPFloat
-setPrecisionUp p = MPLow.precRound MPLow.TowardInf (p2mpfrPrec p)
+setPrecisionUp p = MPLow.set MPLow.Up (p2mpfrPrec p)
setPrecisionDown :: Precision -> MPFloat -> MPFloat
-setPrecisionDown p = MPLow.precRound MPLow.TowardNegInf (p2mpfrPrec p)
+setPrecisionDown p = MPLow.set MPLow.Down (p2mpfrPrec p)