[commit: ghc] ghc-8.6: Fix gcdExtInteger (trac#15350) (767f56605)

git at git.haskell.org git at git.haskell.org
Thu Aug 23 19:56:41 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.6
Link       : http://ghc.haskell.org/trac/ghc/changeset/767f5660529f41788d6df53ad0461a2856f15a85/ghc

>---------------------------------------------------------------

commit 767f5660529f41788d6df53ad0461a2856f15a85
Author: Bodigrim <andrew.lelechenko at gmail.com>
Date:   Sat Jul 7 00:20:10 2018 +0100

    Fix gcdExtInteger (trac#15350)
    
    (cherry picked from commit 7c207c86ab0de955ebec70eeeb366ba0d94acc4a)


>---------------------------------------------------------------

767f5660529f41788d6df53ad0461a2856f15a85
 libraries/integer-gmp/src/GHC/Integer/Type.hs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libraries/integer-gmp/src/GHC/Integer/Type.hs b/libraries/integer-gmp/src/GHC/Integer/Type.hs
index 9ea7c06..9636b9f 100644
--- a/libraries/integer-gmp/src/GHC/Integer/Type.hs
+++ b/libraries/integer-gmp/src/GHC/Integer/Type.hs
@@ -1389,7 +1389,9 @@ gcdExtSBigNat x y = case runS go of (g,s) -> (# g, s #)
   where
     go = do
         g@(MBN# g#) <- newBigNat# gn0#
-        s@(MBN# s#) <- newBigNat# (absI# xn#)
+        -- According to https://gmplib.org/manual/Number-Theoretic-Functions.html#index-mpz_005fgcdext
+        -- abs(s) < abs(y) / (2 g)
+        s@(MBN# s#) <- newBigNat# (absI# yn#)
         I# ssn_# <- liftIO (integer_gmp_gcdext# s# g# x# xn# y# yn#)
         let ssn# = narrowGmpSize# ssn_#
             sn#  = absI# ssn#



More information about the ghc-commits mailing list