exact-pi 0.2.0.0 → 0.2.1.0
raw patch · 3 files changed
+47/−4 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.ExactPi: isExactInteger :: ExactPi -> Bool
+ Data.ExactPi: isExactRational :: ExactPi -> Bool
+ Data.ExactPi: isZero :: ExactPi -> Bool
+ Data.ExactPi: toExactInteger :: ExactPi -> Maybe Integer
+ Data.ExactPi: toExactRational :: ExactPi -> Maybe Rational
Files
- changelog.md +12/−0
- exact-pi.cabal +3/−3
- src/Data/ExactPi.hs +32/−1
+ changelog.md view
@@ -0,0 +1,12 @@+0.2.1.0 +------- +* Added support for converting to exact integers or exact rationals. + +0.2.0.0 +------- +* Removed dependency on groups package, since it appears not to be widely used. +* Fixed a missing case alternative in recip. + +0.1.2.0 +------- +* Added support for GHC 7.8.
exact-pi.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: exact-pi -version: 0.2.0.0 +version: 0.2.1.0 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. @@ -14,7 +14,8 @@ -- copyright: category: Data build-type: Simple -extra-source-files: README.md +extra-source-files: README.md, + changelog.md cabal-version: >=1.10 library @@ -29,4 +30,3 @@ source-repository head type: git location: https://github.com/dmcclean/exact-pi.git -
src/Data/ExactPi.hs view
@@ -19,12 +19,18 @@ ( ExactPi(..), approximateValue, + isZero, isExactZero, - isExactOne + isExactOne, + isExactInteger, + toExactInteger, + isExactRational, + toExactRational ) where import Data.Monoid +import Data.Ratio (numerator, denominator) import Prelude -- | Represents an exact or approximate real value. @@ -39,6 +45,11 @@ approximateValue (Exact z q) = (pi ^ z) * (fromRational q) approximateValue (Approximate x) = x +-- | Identifies whether an 'ExactPi' is an exact or approximate representation of zero. +isZero :: ExactPi -> Bool +isZero (Exact _ 0) = True +isZero (Approximate x) = x == (0 :: Double) + -- | Identifies whether an 'ExactPi' is an exact representation of zero. isExactZero :: ExactPi -> Bool isExactZero (Exact _ 0) = True @@ -48,6 +59,26 @@ isExactOne :: ExactPi -> Bool isExactOne (Exact 0 1) = True isExactOne _ = False + +-- | Identifies whether an 'ExactPi' is an exact representation of an integer. +isExactInteger :: ExactPi -> Bool +isExactInteger (Exact 0 q) | denominator q == 1 = True +isExactInteger _ = False + +-- | Converts an 'ExactPi' to an exact 'Integer' or 'Nothing'. +toExactInteger :: ExactPi -> Maybe Integer +toExactInteger (Exact 0 q) | denominator q == 1 = Just $ numerator q +toExactInteger _ = Nothing + +-- | Identifies whether an 'ExactPi' is an exact representation of a rational. +isExactRational :: ExactPi -> Bool +isExactRational (Exact 0 _) = True +isExactRational _ = False + +-- | Converts an 'ExactPi' to an exact 'Rational' or 'Nothing'. +toExactRational :: ExactPi -> Maybe Rational +toExactRational (Exact 0 q) = Just q +toExactRational _ = Nothing instance Show ExactPi where show (Exact z q) | z == 0 = "Exactly " ++ show q