exact-real 0.4.0.0 → 0.5.0.0
raw patch · 5 files changed
+49/−4 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.CReal.Internal: instance GHC.TypeLits.KnownNat n => GHC.Real.Real (Data.CReal.Internal.CReal n)
Files
- exact-real.cabal +5/−3
- src/Data/CReal/Internal.hs +5/−0
- test/Data/Ratio/Extra.hs +10/−0
- test/Real.hs +22/−0
- test/Test.hs +7/−1
exact-real.cabal view
@@ -1,5 +1,5 @@ name: exact-real-version: 0.4.0.0+version: 0.5.0.0 synopsis: Exact real arithmetic description: please see readme.md license: MIT@@ -40,12 +40,14 @@ main-is: Test.hs other-modules:+ Data.CReal.Extra,+ Data.Monoid.Extra,+ Data.Ratio.Extra, Floating, Fractional, Num, Ord,- Data.CReal.Extra,- Data.Monoid.Extra,+ Real, Test.QuickCheck.Classes.Extra Test.QuickCheck.Extra Test.Tasty.Extra
src/Data/CReal/Internal.hs view
@@ -194,6 +194,11 @@ acosh x = log (x + sqrt (x + 1) * sqrt (x - 1)) atanh x = (log (1 + x) - log (1 - x)) / 2 +-- | 'toRational' returns the CReal n evaluated at a precision of 2^-n+instance KnownNat n => Real (CReal n) where+ toRational x = let p = crealPrecision x+ in x `atPrecision` p % 2^p+ -- | Values of type @CReal p@ are compared for equality at precision @p@. This -- may cause values which differ by less than 2^-p to compare as equal. --
+ test/Data/Ratio/Extra.hs view
@@ -0,0 +1,10 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Data.Ratio.Extra+ ( module Data.Ratio+ ) where++import Data.Ratio+import Test.QuickCheck.Checkers (EqProp(..), eq)++instance Eq a => EqProp (Ratio a) where+ (=-=) = eq
+ test/Real.hs view
@@ -0,0 +1,22 @@+{-# LANGUAGE ScopedTypeVariables #-}++module Real+ ( real+ ) where++import Data.Ratio.Extra ()+import Test.QuickCheck.Checkers (EqProp, inverseL)+import Test.Tasty (testGroup, TestTree)+import Test.Tasty.QuickCheck (testProperty, Arbitrary)++real :: forall a. (Arbitrary a, EqProp a, Show a, Fractional a, Real a) =>+ (a -> Rational) -> TestTree+real maxError = testGroup "Test Real instance" ts+ where ts = [ testProperty "fromRational toRational left inverse"+ (inverseL fromRational (toRational :: a -> Rational))+ , testProperty "toRational fromRational left inverse (within error)"+ (\r -> let x :: a+ x = fromRational r+ r' = toRational x+ in r - r' <= maxError x)+ ]
test/Test.hs view
@@ -4,15 +4,17 @@ module Main (main) where +import Data.Ratio ((%)) import Test.Tasty (testGroup, TestTree)-import Test.Tasty.TH (defaultMainGenerator) import Test.Tasty.QuickCheck (Positive(..), testProperty, (===), Property)+import Test.Tasty.TH (defaultMainGenerator) import Data.CReal.Internal import Data.CReal.Extra () import Floating (floating) import Ord (ord)+import Real (real) -- How many binary digits to use for comparisons TODO: Test with many different -- precisions@@ -30,6 +32,10 @@ {-# ANN test_ord "HLint: ignore Use camelCase" #-} test_ord :: [TestTree] test_ord = [ ord (undefined :: CReal Precision) ]++{-# ANN test_real "HLint: ignore Use camelCase" #-}+test_real :: [TestTree]+test_real = [ real (\x -> 1 % toInteger (crealPrecision (x::CReal Precision))) ] prop_decimalDigits :: Positive Int -> Bool prop_decimalDigits (Positive p) = let d = decimalDigitsAtPrecision p