packages feed

integer-logarithms 1.0.1 → 1.0.2

raw patch · 10 files changed

+51/−158 lines, 10 filesdep ~QuickCheckdep ~tasty-quickcheckPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: QuickCheck, tasty-quickcheck

API changes (from Hackage documentation)

Files

changelog.md view
@@ -1,3 +1,9 @@+1.0.2+-----++- Deprecate `Math.NumberTheory.Power.Integer` and `Math.NumberTheory.Power.Natural` modules+  `(^)` is as good as custom methods.+ 1.0.1 ----- 
integer-logarithms.cabal view
@@ -1,5 +1,5 @@ name:               integer-logarithms-version:            1.0.1+version:            1.0.2 cabal-version:      >= 1.10 author:             Daniel Fischer copyright:          (c) 2011 Daniel Fischer@@ -29,7 +29,8 @@   GHC==7.6.3,   GHC==7.8.4,   GHC==7.10.3,-  GHC==8.0.1+  GHC==8.0.2,+  GHC==8.2.1  extra-source-files  : readme.md changelog.md @@ -47,7 +48,7 @@   default-language: Haskell2010   hs-source-dirs: src   build-depends:-    base >= 4.3 && < 4.10,+    base >= 4.3 && < 4.11,     array >= 0.3 && < 0.6,     ghc-prim < 0.6   if impl(ghc >= 7.10)@@ -97,16 +98,14 @@     integer-logarithms,     tasty >= 0.10 && < 0.12,     tasty-smallcheck >= 0.8 && < 0.9,-    tasty-quickcheck >= 0.8 && < 0.9,+    tasty-quickcheck >= 0.8 && < 0.10,     tasty-hunit >= 0.9 && < 0.10,-    QuickCheck >= 2.9 && < 2.10,+    QuickCheck >= 2.10 && < 2.11,     smallcheck >= 1.1 && < 1.2   if !impl(ghc >= 7.10)     build-depends: nats >= 1.1 && <1.2    other-modules:     Math.NumberTheory.LogarithmsTests-    Math.NumberTheory.Powers.IntegerTests-    Math.NumberTheory.Powers.NaturalTests-  other-modules:     Math.NumberTheory.TestUtils+    Orphans
src/Math/NumberTheory/Logarithms.hs view
@@ -53,9 +53,6 @@ import Data.Array.Base (unsafeAt) #endif -import Math.NumberTheory.Powers.Integer-import Math.NumberTheory.Powers.Natural- -- | Calculate the integer logarithm for an arbitrary base. --   The base must be greater than 1, the second argument, the number --   whose logarithm is sought, must be positive, otherwise an error is thrown.@@ -163,7 +160,7 @@ integerLog10' n   | n < 10      = 0   | n < 100     = 1-  | otherwise   = ex + integerLog10' (n `quot` integerPower 10 ex)+  | otherwise   = ex + integerLog10' (n `quot` 10 ^ ex)     where       ln = I# (integerLog2# n)       -- u/v is a good approximation of log 2/log 10@@ -179,7 +176,7 @@ naturalLog10' n   | n < 10      = 0   | n < 100     = 1-  | otherwise   = ex + naturalLog10' (n `quot` naturalPower 10 ex)+  | otherwise   = ex + naturalLog10' (n `quot` 10 ^ ex)     where       ln = I# (naturalLog2# n)       -- u/v is a good approximation of log 2/log 10@@ -204,7 +201,7 @@                       ex = fromInteger ((fromIntegral u * fromIntegral ln) `quot` fromIntegral v)                   in case u of                       1 -> ln `quot` v      -- a power of 2, easy-                      _ -> ex + integerLogBase' b (n `quot` integerPower b ex)+                      _ -> ex + integerLogBase' b (n `quot` b ^ ex)   | otherwise   = let -- shift b so that 16 <= bi < 32                       bi = fromInteger (b `shiftR` (lb-4))                       -- we choose an approximation of log 2 / log (bi+1) to@@ -219,7 +216,7 @@                       v  = fromIntegral $ logArr `unsafeAt` (ix+1)                       w  = v + u*fromIntegral (lb-4)                       ex = fromInteger ((u * fromIntegral ln) `quot` w)-                  in ex + integerLogBase' b (n `quot` integerPower b ex)+                  in ex + integerLogBase' b (n `quot` b ^ ex)     where       lb = integerLog2' b       ln = integerLog2' n@@ -240,7 +237,7 @@                       ex = fromNatural ((fromIntegral u * fromIntegral ln) `quot` fromIntegral v)                   in case u of                       1 -> ln `quot` v      -- a power of 2, easy-                      _ -> ex + naturalLogBase' b (n `quot` naturalPower b ex)+                      _ -> ex + naturalLogBase' b (n `quot` b ^ ex)   | otherwise   = let -- shift b so that 16 <= bi < 32                       bi = fromNatural (b `shiftR` (lb-4))                       -- we choose an approximation of log 2 / log (bi+1) to@@ -255,7 +252,7 @@                       v  = fromIntegral $ logArr `unsafeAt` (ix+1)                       w  = v + u*fromIntegral (lb-4)                       ex = fromNatural ((u * fromIntegral ln) `quot` w)-                  in ex + naturalLogBase' b (n `quot` naturalPower b ex)+                  in ex + naturalLogBase' b (n `quot` b ^ ex)     where       lb = naturalLog2' b       ln = naturalLog2' n
src/Math/NumberTheory/Powers/Integer.hs view
@@ -10,15 +10,15 @@ -- or 'Word' exponent. -- {-# LANGUAGE CPP          #-}-{-# LANGUAGE MagicHash    #-}-{-# LANGUAGE BangPatterns #-} module Math.NumberTheory.Powers.Integer+    {-# DEPRECATED "It is no faster than (^)" #-}     ( integerPower     , integerWordPower     ) where -import GHC.Exts-import GHC.Integer.Logarithms.Compat (wordLog2#)+#if !MIN_VERSION_base(4,8,0)+import Data.Word+#endif  -- | Power of an 'Integer' by the left-to-right repeated squaring algorithm. --   This needs two multiplications in each step while the right-to-left@@ -34,29 +34,10 @@ --   /Warning:/ No check for the negativity of the exponent is performed, --   a negative exponent is interpreted as a large positive exponent. integerPower :: Integer -> Int -> Integer-integerPower b (I# e#) = power b (int2Word# e#)+integerPower = (^)+{-# DEPRECATED integerPower "Use (^) instead" #-}  -- | Same as 'integerPower', but for exponents of type 'Word'. integerWordPower :: Integer -> Word -> Integer-integerWordPower b (W# w#) = power b w#--power :: Integer -> Word# -> Integer-power b w#-  | isTrue# (w# `eqWord#` 0##) = 1-  | isTrue# (w# `eqWord#` 1##) = b-  | otherwise           = go (wordLog2# w# -# 1#) b (b*b)-    where-      go 0# l h = if isTrue# ((w# `and#` 1##) `eqWord#` 0##) then l*l else (l*h)-      go i# l h-        | w# `hasBit#` i#   = go (i# -# 1#) (l*h) (h*h)-        | otherwise         = go (i# -# 1#) (l*l) (l*h)---- | A raw version of testBit for 'Word#'.-hasBit# :: Word# -> Int# -> Bool-hasBit# w# i# = isTrue# (((w# `uncheckedShiftRL#` i#) `and#` 1##) `neWord#` 0##)--#if __GLASGOW_HASKELL__ < 707--- The times they are a-changing. The types of primops too :(-isTrue# :: Bool -> Bool-isTrue# = id-#endif+integerWordPower = (^)+{-# DEPRECATED integerWordPower "Use (^) instead" #-}
src/Math/NumberTheory/Powers/Natural.hs view
@@ -10,16 +10,17 @@ -- or 'Word' exponent. -- {-# LANGUAGE CPP          #-}-{-# LANGUAGE MagicHash    #-}-{-# LANGUAGE BangPatterns #-} module Math.NumberTheory.Powers.Natural+    {-# DEPRECATED "It is no faster than (^)" #-}     ( naturalPower     , naturalWordPower     ) where -import GHC.Exts+#if !MIN_VERSION_base(4,8,0)+import Data.Word+#endif+ import Numeric.Natural-import GHC.Integer.Logarithms.Compat (wordLog2#)  -- | Power of an 'Natural' by the left-to-right repeated squaring algorithm. --   This needs two multiplications in each step while the right-to-left@@ -35,29 +36,10 @@ --   /Warning:/ No check for the negativity of the exponent is performed, --   a negative exponent is interpreted as a large positive exponent. naturalPower :: Natural -> Int -> Natural-naturalPower b (I# e#) = power b (int2Word# e#)+naturalPower = (^)+{-# DEPRECATED naturalPower "Use (^) instead" #-}  -- | Same as 'naturalPower', but for exponents of type 'Word'. naturalWordPower :: Natural -> Word -> Natural-naturalWordPower b (W# w#) = power b w#--power :: Natural -> Word# -> Natural-power b w#-  | isTrue# (w# `eqWord#` 0##) = 1-  | isTrue# (w# `eqWord#` 1##) = b-  | otherwise           = go (wordLog2# w# -# 1#) b (b*b)-    where-      go 0# l h = if isTrue# ((w# `and#` 1##) `eqWord#` 0##) then l*l else (l*h)-      go i# l h-        | w# `hasBit#` i#   = go (i# -# 1#) (l*h) (h*h)-        | otherwise         = go (i# -# 1#) (l*l) (l*h)---- | A raw version of testBit for 'Word#'.-hasBit# :: Word# -> Int# -> Bool-hasBit# w# i# = isTrue# (((w# `uncheckedShiftRL#` i#) `and#` 1##) `neWord#` 0##)--#if __GLASGOW_HASKELL__ < 707--- The times they are a-changing. The types of primops too :(-isTrue# :: Bool -> Bool-isTrue# = id-#endif+naturalWordPower = (^)+{-# DEPRECATED naturalWordPower "Use (^) instead" #-}
test-suite/Math/NumberTheory/LogarithmsTests.hs view
@@ -27,6 +27,9 @@ import Math.NumberTheory.Logarithms import Math.NumberTheory.TestUtils +-- Arbitrary Natural+import Orphans ()+ -- | Check that 'integerLogBase' returns the largest integer @l@ such that @b@ ^ @l@ <= @n@ and @b@ ^ (@l@+1) > @n@. integerLogBaseProperty :: Positive Integer -> Positive Integer -> Bool integerLogBaseProperty (Positive b) (Positive n) = b == 1 || b ^ l <= n && b ^ (l + 1) > n
− test-suite/Math/NumberTheory/Powers/IntegerTests.hs
@@ -1,41 +0,0 @@--- |--- Module:      Math.NumberTheory.Powers.IntegerTests--- Copyright:   (c) 2016 Andrew Lelechenko--- Licence:     MIT--- Maintainer:  Andrew Lelechenko <andrew.lelechenko@gmail.com>--- Stability:   Provisional------ Tests for Math.NumberTheory.Powers.Integer-----{-# LANGUAGE CPP #-}--{-# OPTIONS_GHC -fno-warn-type-defaults #-}--module Math.NumberTheory.Powers.IntegerTests-  ( testSuite-  ) where--import Test.Tasty--#if MIN_VERSION_base(4,8,0)-#else-import Data.Word-#endif--import Math.NumberTheory.Powers.Integer-import Math.NumberTheory.TestUtils---- | Check that 'integerPower' == '^'.-integerPowerProperty :: Integer -> Power Int -> Bool-integerPowerProperty a (Power b) = integerPower a b == a ^ b---- | Check that 'integerWordPower' == '^'.-integerWordPowerProperty :: Integer -> Power Word -> Bool-integerWordPowerProperty a (Power b) = integerWordPower a b == a ^ b--testSuite :: TestTree-testSuite = testGroup "Integer"-  [ testSmallAndQuick "integerPower"     integerPowerProperty-  , testSmallAndQuick "integerWordPower" integerWordPowerProperty-  ]
− test-suite/Math/NumberTheory/Powers/NaturalTests.hs
@@ -1,42 +0,0 @@--- |--- Module:      Math.NumberTheory.Powers.NaturalTests--- Copyright:   (c) 2016 Andrew Lelechenko--- Licence:     MIT--- Maintainer:  Andrew Lelechenko <andrew.lelechenko@gmail.com>--- Stability:   Provisional------ Tests for Math.NumberTheory.Powers.Natural-----{-# LANGUAGE CPP #-}--{-# OPTIONS_GHC -fno-warn-type-defaults #-}--module Math.NumberTheory.Powers.NaturalTests-  ( testSuite-  ) where--import Test.Tasty--#if MIN_VERSION_base(4,8,0)-#else-import Data.Word-#endif--import Math.NumberTheory.Powers.Natural-import Numeric.Natural-import Math.NumberTheory.TestUtils---- | Check that 'naturalPower' == '^'.-naturalPowerProperty :: Natural -> Power Int -> Bool-naturalPowerProperty a (Power b) = naturalPower a b == a ^ b---- | Check that 'naturalWordPower' == '^'.-naturalWordPowerProperty :: Natural -> Power Word -> Bool-naturalWordPowerProperty a (Power b) = naturalWordPower a b == a ^ b--testSuite :: TestTree-testSuite = testGroup "Natural"-  [ testSmallAndQuick "naturalPower"     naturalPowerProperty-  , testSmallAndQuick "naturalWordPower" naturalWordPowerProperty-  ]
+ test-suite/Orphans.hs view
@@ -0,0 +1,12 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Orphans () where++import Numeric.Natural (Natural)+import Test.QuickCheck (Arbitrary (..))++-- | The QuickCheck-2.10 doesn't define the Arbitrary Natural instance+-- We define own instance (and not use quickcheck-instance) to break+-- the cycle in tests.+instance Arbitrary Natural where+    arbitrary = fmap (fromInteger . abs) arbitrary+    shrink = map (fromInteger . abs) . shrink . fromIntegral
test-suite/Test.hs view
@@ -1,8 +1,6 @@ import Test.Tasty  import qualified Math.NumberTheory.LogarithmsTests as Logarithms-import qualified Math.NumberTheory.Powers.IntegerTests as PowerInteger-import qualified Math.NumberTheory.Powers.NaturalTests as PowerNatural  main :: IO () main = defaultMain tests@@ -10,6 +8,4 @@ tests :: TestTree tests = testGroup "All"     [ Logarithms.testSuite-    , PowerInteger.testSuite-    , PowerNatural.testSuite     ]