exact-real 0.3.0.0 → 0.4.0.0
raw patch · 3 files changed
+17/−13 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- exact-real.cabal +1/−1
- src/Data/CReal/Internal.hs +11/−12
- test/Test.hs +5/−0
exact-real.cabal view
@@ -1,5 +1,5 @@ name: exact-real-version: 0.3.0.0+version: 0.4.0.0 synopsis: Exact real arithmetic description: please see readme.md license: MIT
src/Data/CReal/Internal.hs view
@@ -303,18 +303,17 @@ -- | @rationalToDecimal p x@ returns a string representing @x@ at @p@ decimal -- places. rationalToDecimal :: Int -> Rational -> String-rationalToDecimal places r = s- where ds = show ((numerator r * 10^places) /. denominator r)- (is, fs) = splitAt (length ds - places) ds- is' = case is of- "" -> "0"- "-" -> "-0"- _ -> is- suff = case places of- 0 -> ""- _ -> '.' : take places (fs ++ repeat '0')- s = is' ++ suff+rationalToDecimal places r = p ++ is ++ if places > 0 then "." ++ fs else ""+ where r' = abs r+ p = case signum r of+ -1 -> "-"+ _ -> ""+ ds = show ((numerator r' * 10^places) /. denominator r')+ l = length ds+ (is, fs) = if | l <= places -> ("0", replicate (places - l) '0' ++ ds)+ | otherwise -> splitAt (length ds - places) ds + -- -- Integer operations --@@ -369,7 +368,7 @@ -- | Apply 'negate' to every other element, starting with the second -- -- >>> alternateSign [1..5]--- [1, -2, 3, -4, 5]+-- [1,-2,3,-4,5] alternateSign :: Num a => [a] -> [a] alternateSign = zipWith ($) (cycle [id, negate])
test/Test.hs view
@@ -45,6 +45,11 @@ prop_shiftR :: CReal Precision -> Int -> Property prop_shiftR x s = x `shiftR` s === x / 2 ** fromIntegral s +prop_showNumDigits :: Positive Int -> Rational -> Property+prop_showNumDigits (Positive places) x =+ let s = rationalToDecimal places x+ in length (dropWhile (/= '.') s) === places + 1+ main :: IO () main = $(defaultMainGenerator)