packages feed

exact-pi 0.5.0.2 → 0.5.1.0

raw patch · 8 files changed

+80/−75 lines, 8 filesdep +infinite-listdep −semigroupsdep ~basedep ~numtype-dkdep ~tasty-quickchecksetup-changedPVP ok

version bump matches the API change (PVP)

Dependencies added: infinite-list

Dependencies removed: semigroups

Dependency ranges changed: base, numtype-dk, tasty-quickcheck

API changes (from Hackage documentation)

Files

README.md view
@@ -1,6 +1,5 @@ # exact-pi Exact rational multiples of pi (and integer powers of pi) in Haskell -[![Build Status](https://travis-ci.org/dmcclean/exact-pi.svg?branch=master)](https://travis-ci.org/dmcclean/exact-pi) [![Hackage Version](https://img.shields.io/hackage/v/exact-pi.svg)](http://hackage.haskell.org/package/exact-pi) [![Stackage version](https://www.stackage.org/package/exact-pi/badge/lts?label=Stackage)](https://www.stackage.org/package/exact-pi)
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
changelog.md view
@@ -1,3 +1,7 @@+0.5.1.0+-------+* Fix warnings.+ 0.5.0.2 ------- * Support GHC 9.4.
exact-pi.cabal view
@@ -1,54 +1,55 @@-name:                exact-pi-version:             0.5.0.2-synopsis:            Exact rational multiples of pi (and integer powers of pi)-description:         Provides an exact representation for rational multiples of pi alongside an approximate representation of all reals.-                     Useful for storing and computing with conversion factors between physical units.-homepage:            https://github.com/dmcclean/exact-pi/-bug-reports:         https://github.com/dmcclean/exact-pi/issues/-license:             MIT-license-file:        LICENSE-author:              Douglas McClean-maintainer:          douglas.mcclean@gmail.com-category:            Data-build-type:          Simple-extra-source-files:  README.md,-                     changelog.md-cabal-version:       >=1.10-tested-with:         GHC == 7.8.4,-                     GHC == 7.10.3,-                     GHC == 8.0.2,-                     GHC == 8.2.2,-                     GHC == 8.4.3,-                     GHC == 8.6.1+cabal-version:      >=1.10+name:               exact-pi+version:            0.5.1.0+license:            MIT+license-file:       LICENSE+maintainer:         douglas.mcclean@gmail.com+author:             Douglas McClean+tested-with:+    ghc ==9.14.1 ghc ==9.12.2 ghc ==9.10.3 ghc ==9.8.4 ghc ==9.6.7 ghc ==9.4.8+    ghc ==9.2.8 ghc ==9.0.2 ghc ==8.10.7 ghc ==8.8.4 ghc ==8.6.5 ghc ==8.4.4++homepage:           https://github.com/dmcclean/exact-pi/+bug-reports:        https://github.com/dmcclean/exact-pi/issues/+synopsis:           Exact rational multiples of pi (and integer powers of pi)+description:+    Provides an exact representation for rational multiples of pi alongside an approximate representation of all reals.+    Useful for storing and computing with conversion factors between physical units.++category:           Data+build-type:         Simple+extra-source-files:+    README.md+    changelog.md++source-repository head+    type:     git+    location: https://github.com/dmcclean/exact-pi.git+ library-  exposed-modules:     Data.ExactPi,-                       Data.ExactPi.TypeLevel-  build-depends:       base >=4.7 && <5,-                       numtype-dk >= 0.5-  if impl(ghc <8.0)+    exposed-modules:+        Data.ExactPi+        Data.ExactPi.TypeLevel++    hs-source-dirs:   src+    default-language: Haskell2010+    ghc-options:      -Wall     build-depends:-                       semigroups >=0.8-  ghc-options:         -Wall-  hs-source-dirs:      src-  default-language:    Haskell2010+        base >=4.11 && <5,+        numtype-dk >=0.5 && <0.6,+        infinite-list <0.2  test-suite spec-  main-is:             Test.hs-  build-depends:       base >=4.7 && <5,-                       exact-pi,-                       numtype-dk >= 0.5,-                       QuickCheck >=2.10,-                       tasty >=0.10,-                       tasty-hunit >=0.9 && <0.11,-                       tasty-quickcheck >= 0.9 && <0.11-  if impl(ghc < 8.0)-    build-depends:     semigroups >=0.9 && < 1.0-  other-modules:       TestUtils-  type:                exitcode-stdio-1.0-  ghc-options:         -Wall-  hs-source-dirs:      test-suite-  default-language:    Haskell2010--source-repository head-  type:                git-  location:            https://github.com/dmcclean/exact-pi.git+    type:             exitcode-stdio-1.0+    main-is:          Test.hs+    hs-source-dirs:   test-suite+    other-modules:    TestUtils+    default-language: Haskell2010+    ghc-options:      -Wall+    build-depends:+        base >=4.11 && <5,+        exact-pi,+        QuickCheck >=2.10,+        tasty >=0.10,+        tasty-hunit >=0.9 && <0.11,+        tasty-quickcheck >=0.9 && <0.12
src/Data/ExactPi.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE RankNTypes          #-} {-# LANGUAGE ParallelListComp    #-}+{-# LANGUAGE PostfixOperators    #-}  {-# OPTIONS_HADDOCK show-extensions #-} @@ -35,6 +36,8 @@ ) where +import Data.List.Infinite (Infinite(..), (...))+import qualified Data.List.Infinite as Inf import Data.Monoid import Data.Ratio ((%), numerator, denominator) import Data.Semigroup@@ -49,7 +52,7 @@ -- This uses the value of `pi` supplied by the destination type, to provide the appropriate -- precision. approximateValue :: Floating a => ExactPi -> a-approximateValue (Exact z q) = (pi ^^ z) * (fromRational q)+approximateValue (Exact z q) = (pi ^^ z) * fromRational q approximateValue (Approximate x) = x  -- | Identifies whether an 'ExactPi' is an exact or approximate representation of zero.@@ -108,18 +111,19 @@ rationalApproximations (Exact _ 0)     = [0] rationalApproximations (Exact 0 q)     = [q] rationalApproximations (Exact z q)-  | even z    = [q * 10005^^k * c^^z     | c <- chudnovsky]-  | otherwise = [q * 10005^^k * c^^z * r | c <- chudnovsky | r <- rootApproximation]+  | even z    = Inf.toList $ fmap (\c -> q * 10005^^k * c^^z) chudnovsky+  | otherwise = Inf.toList $ Inf.zipWith (\c r -> q * 10005^^k * c^^z * r)  chudnovsky rootApproximation   where k = z `div` 2 -chudnovsky :: [Rational]-chudnovsky = [426880 / s | s <- partials]-  where lk = iterate (+545140134) 13591409-        xk = iterate (*(-262537412640768000)) 1-        kk = iterate (+12) 6-        mk = 1: [m * ((k^(3::Int) - 16*k) % (n+1)^(3::Int)) | m <- mk | k <- kk | n <- [0..]]-        values = [m * l / x | m <- mk | l <- lk | x <- xk]-        partials = scanl1 (+) values+chudnovsky :: Infinite Rational+chudnovsky = fmap (426880 /) partials+  where+    lk = Inf.iterate (+545140134) 13591409+    xk = Inf.iterate (*(-262537412640768000)) 1+    kk = Inf.iterate (+12) 6+    mk = 1 :< Inf.zipWith3 (\m k n -> m * ((k^(3::Int) - 16*k) % (n+1)^(3::Int))) mk kk (0...)+    values = Inf.zipWith3 (\m l x -> m * l / x) mk lk xk+    partials = Inf.scanl1 (+) values  -- | Given an infinite converging sequence of rationals, find their limit. -- Takes a comparison function to determine when convergence is close enough.@@ -142,10 +146,11 @@ -- Chudnovsky's series provides no more than 15 digits -- per iteration, so the root approximation should not -- have a more rapid rate of convergence.-rootApproximation :: [Rational]-rootApproximation = map head . iterate (drop 4) $ go 1 0 100 1 40+rootApproximation :: Infinite Rational+rootApproximation = fmap Inf.head . Inf.iterate (Inf.drop 4) $ go 1 0 100 1 40   where-    go pk' qk' pk qk a = (pk % qk): go pk qk (pk' + a*pk) (qk' + a*qk) (240-a)+    go :: Integer -> Integer -> Integer -> Integer -> Integer -> Infinite Rational+    go pk' qk' pk qk a = (pk % qk) :< go pk qk (pk' + a*pk) (qk' + a*qk) (240-a)  instance Show ExactPi where   show (Exact z q) | z == 0 = "Exactly " ++ show q@@ -197,9 +202,8 @@  -- | The multiplicative semigroup over 'Rational's augmented with multiples of 'pi'. instance Semigroup ExactPi where-  (<>) = mappend+  (<>) = (*)  -- | The multiplicative monoid over 'Rational's augmented with multiples of 'pi'. instance Monoid ExactPi where   mempty = 1-  mappend = (*)
src/Data/ExactPi/TypeLevel.hs view
@@ -4,7 +4,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-}
test-suite/Test.hs view
@@ -29,9 +29,9 @@   where     MkFixed x = getValue (Exact 2 1) :: Fixed (E 3647) --- test first term matches formula of chudnovsky's algorithm+-- test first term matches formula of Chudnovsky's algorithm firstApproximation :: Assertion-firstApproximation = head (rationalApproximations (Exact 2 1)) @?= (426880 % 13591409)^2 * 10005+firstApproximation = take 1 (rationalApproximations (Exact 2 1)) @?= [(426880 % 13591409)^2 * 10005]  -- pi tests piDouble :: Assertion
test-suite/TestUtils.hs view
@@ -8,10 +8,10 @@   , E   ) where -import Data.Proxy   (Proxy)-import Data.List    (foldl')+import Prelude hiding (Foldable(..)) import Data.Fixed   (mod', HasResolution(..), Fixed)-+import Data.Foldable+import Data.Proxy   (Proxy) import GHC.TypeLits (Nat, KnownNat, SomeNat(..), natVal, someNatVal)  import Data.ExactPi