From 9d0f1041986af52962b74540e70a9f49d5fc56c0 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sun, 1 Jun 2008 12:07:59 +0000 Subject: [PATCH] Tweak the definition of (^) again This fixes trac #2306 (do the minimum number of (*)s), and also means that we don't use the value of (1 :: a) which causes problems if the Num a definition isn't complete. --- GHC/Real.lhs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/GHC/Real.lhs b/GHC/Real.lhs index 8f39cf8..b24ab7d 100644 --- a/GHC/Real.lhs +++ b/GHC/Real.lhs @@ -408,11 +408,15 @@ odd = not . even (^) :: (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 + | otherwise = f x0 y0 + where -- f : x0 ^ y0 = x ^ y + f x y | even y = f (x * x) (y `quot` 2) + | y == 1 = x + | otherwise = g (x * x) ((y - 1) `quot` 2) x + -- g : x0 ^ y0 = (x ^ y) * z + g x y z | even y = g (x * x) (y `quot` 2) z | y == 1 = x * z - | otherwise = f (x * x) ((y - 1) `quot` 2) (x * z) + | otherwise = g (x * x) ((y - 1) `quot` 2) (x * z) -- | raise a number to an integral power {-# SPECIALISE (^^) :: -- 1.7.10.4