Skip to content

Commit 65dde34

Browse files
committed
Unroll exponentation uo to 5 for inlining.
1 parent 54fbbae commit 65dde34

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Statistics/Sample/Fold.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ import Prelude hiding ((^), sum)
139139

140140
-- (^) operator from Prelude is just slow.
141141
(^) :: Double -> Int -> Double
142-
x ^ 1 = x
142+
!x ^ 1 = x
143+
x ^ 2 = x * x
144+
x ^ 3 = x * x * x
145+
x ^ 4 = (x * x) * (x * x)
146+
x ^ 5 = (x * x) * x * (x * x)
143147
-- x ^ n = x * (x ^ (n-1))
144148
x0 ^ n0 = go (n0-1) x0 where
145149
go 0 !acc = acc

0 commit comments

Comments
 (0)