integer-roots 1.0.0.1 → 1.0.1.0
raw patch · 6 files changed
+53/−6 lines, 6 files
Files
- Math/NumberTheory/Roots/General.hs +15/−2
- Math/NumberTheory/Utils/BitMask.hs +12/−1
- README.md +1/−1
- changelog.md +4/−0
- integer-roots.cabal +4/−2
- test-suite/Math/NumberTheory/TestUtils.hs +17/−0
Math/NumberTheory/Roots/General.hs view
@@ -27,6 +27,9 @@ #if MIN_VERSION_base(4,16,0) import GHC.Exts (word16ToWord#) #endif+#ifdef WORDS_BIGENDIAN+import GHC.Exts (byteSwap#)+#endif import GHC.Integer.GMP.Internals (Integer(..), shiftLInteger, shiftRInteger) import GHC.Integer.Logarithms (integerLog2#) import Numeric.Natural (Natural)@@ -255,11 +258,21 @@ smallOddPrimes :: [Integer] smallOddPrimes = takeWhile (< spBound)+ $ map (\(I# k#) -> S# (word2Int# ( #if MIN_VERSION_base(4,16,0)- $ map (\(I# k#) -> S# (word2Int# (word16ToWord# (indexWord16OffAddr# smallPrimesAddr# k#))))+#ifdef WORDS_BIGENDIAN+ byteSwap16# (word16ToWord# (indexWord16OffAddr# smallPrimesAddr# k#)) #else- $ map (\(I# k#) -> S# (word2Int# (indexWord16OffAddr# smallPrimesAddr# k#)))+ word16ToWord# (indexWord16OffAddr# smallPrimesAddr# k#) #endif+#else+#ifdef WORDS_BIGENDIAN+ byteSwap16# (indexWord16OffAddr# smallPrimesAddr# k#)+#else+ indexWord16OffAddr# smallPrimesAddr# k#+#endif+#endif+ ))) [1 .. smallPrimesLength - 1] where !(Ptr smallPrimesAddr#) = smallPrimesPtr
Math/NumberTheory/Utils/BitMask.hs view
@@ -7,6 +7,7 @@ -- Bit mask utilities. -- +{-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} module Math.NumberTheory.Utils.BitMask@@ -14,8 +15,13 @@ -- , vectorToAddrLiteral ) where +#include "MachDeps.h"+ import Data.Bits (countTrailingZeros, finiteBitSize, testBit, (.&.)) import GHC.Exts (Int(..), Word(..), Ptr(..), iShiftRL#, indexWordOffAddr#)+#ifdef WORDS_BIGENDIAN+import GHC.Exts (byteSwap#)+#endif -- import Data.Bits (unsafeShiftL) -- import Data.List (unfoldr)@@ -27,7 +33,12 @@ fbs = finiteBitSize (0 :: Word) logFbs# = case countTrailingZeros fbs of I# l# -> l#- word = W# (indexWordOffAddr# addr# (i# `iShiftRL#` logFbs#))+ word# = indexWordOffAddr# addr# (i# `iShiftRL#` logFbs#)+#ifdef WORDS_BIGENDIAN+ word = W# (byteSwap# word#)+#else+ word = W# word#+#endif -- vectorToAddrLiteral :: [Bool] -> String -- vectorToAddrLiteral = map (chr . toByte . padTo8) . unfoldr go
README.md view
@@ -1,4 +1,4 @@-# integer-roots [](https://github.com/Bodigrim/integer-roots/actions?query=workflow%3AHaskell-CI) [](https://hackage.haskell.org/package/integer-roots) [](https://matrix.hackage.haskell.org/package/integer-roots) [](http://stackage.org/lts/package/integer-roots) [](http://stackage.org/nightly/package/integer-roots)+# integer-roots [](https://hackage.haskell.org/package/integer-roots) [](http://stackage.org/lts/package/integer-roots) [](http://stackage.org/nightly/package/integer-roots) Calculating integer roots and testing perfect powers of arbitrary precision.
changelog.md view
@@ -1,3 +1,7 @@+# 1.0.1.0++* Fixes for big-endian architectures.+ # 1.0.0.1 * Compatibility fixes for GHC 9.2.
integer-roots.cabal view
@@ -1,5 +1,5 @@ name: integer-roots-version: 1.0.0.1+version: 1.0.1.0 cabal-version: >=1.10 build-type: Simple license: MIT@@ -12,7 +12,7 @@ description: Calculating integer roots and testing perfect powers of arbitrary precision. Originally part of <https://hackage.haskell.org/package/arithmoi arithmoi> package. category: Math, Algorithms, Number Theory author: Daniel Fischer, Andrew Lelechenko-tested-with: GHC ==8.0.2 GHC ==8.2.2 GHC ==8.4.4 GHC ==8.6.5 GHC ==8.8.4 GHC ==8.10.4 GHC ==9.0.1+tested-with: GHC ==8.0.2 GHC ==8.2.2 GHC ==8.4.4 GHC ==8.6.5 GHC ==8.8.4 GHC ==8.10.7 GHC ==9.0.1 GHC ==9.2.1 extra-source-files: changelog.md README.md@@ -62,6 +62,8 @@ ghc-options: -Wall -Widentities -Wcompat test-suite integer-roots-doctests+ if impl(ghc >= 9.2)+ buildable: False type: exitcode-stdio-1.0 main-is: Doctest.hs hs-source-dirs: test-suite
test-suite/Math/NumberTheory/TestUtils.hs view
@@ -8,6 +8,7 @@ -- {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}@@ -51,6 +52,22 @@ instance Arbitrary Natural where arbitrary = fromInteger <$> (arbitrary `suchThat` (>= 0)) shrink = map fromInteger . filter (>= 0) . shrink . toInteger++#if !MIN_VERSION_smallcheck(1,2,0)+instance Functor NonNegative where+ fmap f (NonNegative x) = NonNegative (f x)++instance (Num a, Bounded a) => Bounded (NonNegative a) where+ minBound = NonNegative 0+ maxBound = NonNegative (maxBound :: a)++instance Functor Positive where+ fmap f (Positive x) = Positive (f x)++instance (Num a, Bounded a) => Bounded (Positive a) where+ minBound = Positive 1+ maxBound = Positive (maxBound :: a)+#endif -------------------------------------------------------------------------------