Debian Codegraph @

src/Math/NumberTheory/Powers/Natural.hs

raw
1 -- |
2 -- Module: Math.NumberTheory.Powers.Natural
3 -- Copyright: (c) 2011-2014 Daniel Fischer
4 -- Licence: MIT
5 -- Maintainer: Daniel Fischer <[email protected]>
6 -- Stability: Provisional
7 -- Portability: Non-portable (GHC extensions)
8 --
9 -- Potentially faster power function for 'Natural' base and 'Int'
10 -- or 'Word' exponent.
11 --
12 {-# LANGUAGE Safe #-}
13 module Math.NumberTheory.Powers.Natural
14 {-# DEPRECATED "It is no faster than (^)" #-}
15 ( naturalPower
16 , naturalWordPower
17 ) where
18
19 import Numeric.Natural (Natural)
20
21 -- | Power of an 'Natural' by the left-to-right repeated squaring algorithm.
22 -- This needs two multiplications in each step while the right-to-left
23 -- algorithm needs only one multiplication for 0-bits, but here the
24 -- two factors always have approximately the same size, which on average
25 -- gains a bit when the result is large.
26 --
27 -- For small results, it is unlikely to be any faster than '(^)', quite
28 -- possibly slower (though the difference shouldn't be large), and for
29 -- exponents with few bits set, the same holds. But for exponents with
30 -- many bits set, the speedup can be significant.
31 --
32 -- /Warning:/ No check for the negativity of the exponent is performed,
33 -- a negative exponent is interpreted as a large positive exponent.
34 naturalPower :: Natural -> Int -> Natural
35 naturalPower = (^)
36 {-# DEPRECATED naturalPower "Use (^) instead" #-}
37
38 -- | Same as 'naturalPower', but for exponents of type 'Word'.
39 naturalWordPower :: Natural -> Word -> Natural
40 naturalWordPower = (^)
41 {-# DEPRECATED naturalWordPower "Use (^) instead" #-}