#1687: A faster (^)-function.
---------------------------------------+------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: igloo
Type: bug | Status: new
Priority: normal | Milestone: _|_
Component: Prelude | Version: 6.6.1
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: x86
Os: Linux |
---------------------------------------+------------------------------------
Changes (by igloo):
* milestone: 6.8 branch => _|_
Comment:
I've changed the definition to:
{{{
(^) :: (Num a, Integral b) => a -> b -> a
x0 ^ y0 | y0 < 0 = error "Negative exponent"
| y0 == 0 = 1
| otherwise = f x0 y0 1
where -- x0 ^ y0 = (x ^ y) * z
f x y z | even y = f (x * x) (y `quot` 2) z
| y == 1 = x * z
| otherwise = f (x * x) ((y - 1) `quot` 2) (x * z)
}}}
which is as fast as I've seen for `Int`, and matches your definition's
performance for `Integer` when computing {{{(2^(2^27)) `mod` 2}}}, but
it's about half the speed of your definition when computing
{{{(2^((2^27)-1)) `mod` 2}}}.
I don't know why that is - I can't see a reason at the core/STG level.
I'll leave the ticket open, but milestone _|_, in case anyone wants to
look into it.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1687#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs