fixedprec 0.2.1.0 → 0.2.1.1
raw patch · 3 files changed
+46/−17 lines, 3 files
Files
- ChangeLog +7/−0
- Data/Number/FixedPrec.hs +19/−1
- fixedprec.cabal +20/−16
ChangeLog view
@@ -1,5 +1,12 @@ ChangeLog +v0.2.1.1 2014/02/05+ (2014/02/04) PS1 - improved efficiency of square root.+ (2014/02/04) PS1 - added profiling options.++v0.2.1.0 2013/12/11+ (2013/12/11) PS1 - added Random instance for FixedPrec.+ v0.2 2013/06/30 (2013/06/30) PS1 - fixed cabal compilation warnings. (2013/05/29) PS1 - check for non-positive argument in floorlog.
Data/Number/FixedPrec.hs view
@@ -57,18 +57,36 @@ decshiftL :: Int -> Integer -> Integer decshiftL n x = x * 10^n +-- | Return 1 + the position of the leftmost \"1\" bit of a+-- non-negative 'Integer'. Do this in time O(/n/ log /n/), where /n/+-- is the size of the integer (in digits).+hibit :: Integer -> Int+hibit 0 = 0+hibit n = aux 1 where+ aux k + | n >= 2^k = aux (2*k)+ | otherwise = aux2 k (k `div` 2) -- 2^(k/2) <= n < 2^k+ aux2 upper lower + | upper - lower < 2 = upper+ | n >= 2^middle = aux2 upper middle+ | otherwise = aux2 middle lower+ where+ middle = (upper + lower) `div` 2+ -- | For /n/ ≥ 0, return the floor of the square root of /n/. This is -- done using integer arithmetic, so there are no rounding errors. intsqrt :: (Integral n) => n -> n intsqrt n | n <= 0 = 0- | otherwise = iterate 1 + | otherwise = iterate a where iterate m | m_sq <= n && m_sq + 2*m + 1 > n = m | otherwise = iterate ((m + n `div` m) `div` 2) where m_sq = m*m+ a = 2^(b `div` 2)+ b = hibit (fromIntegral n) -- ---------------------------------------------------------------------- -- ** Other general-purpose functions
fixedprec.cabal view
@@ -1,16 +1,17 @@-Name: fixedprec-Version: 0.2.1.0-License: BSD3+name: fixedprec+-- Don't forget to update the ChangeLog+version: 0.2.1.1+license: BSD3 cabal-version: >= 1.8-Build-type: Simple-License-file: LICENSE-Copyright: Copyright (c) 2013 Peter Selinger-Author: Peter Selinger-Maintainer: selinger@mathstat.dal.ca-Stability: beta-Category: Data, Math-Synopsis: A fixed-precision real number type-Description:+build-type: Simple+license-file: LICENSE+copyright: Copyright (c) 2013-2014 Peter Selinger+author: Peter Selinger+maintainer: selinger@mathstat.dal.ca+stability: beta+category: Data, Math+synopsis: A fixed-precision real number type+description: A reasonably efficient implementation of arbitrary-but-fixed precision real numbers. This is inspired by, and partly based on, Data.Number.Fixed and Data.Number.CReal, but more efficient.@@ -18,15 +19,18 @@ extra-source-files: ChangeLog -Library- Build-Depends:+library+ build-depends: base >= 3 && < 5, random ==1.0.* - Exposed-modules:+ exposed-modules: Data.Number.FixedPrec - Ghc-Options:+ ghc-options: -Wall -fno-warn-name-shadowing -fno-warn-unused-matches -fno-warn-type-defaults++ ghc-prof-options:+ -prof -auto-all