Ticket #3304: 0001-Change-gcd-to-reduce-occurrences-of-negative-results.patch

File 0001-Change-gcd-to-reduce-occurrences-of-negative-results.patch, 905 bytes (added by daniel.is.fischer, 3 years ago)

abs the result of gcd to avoid negative results where possible

  • GHC/Real.lhs

    From 799debe8d71768560322ca5aabecbe7f94eaa12c Mon Sep 17 00:00:00 2001
    From: Daniel Fischer <daniel.is.fischer@googlemail.com>
    Date: Mon, 30 May 2011 03:12:37 +0200
    Subject: [PATCH] Change gcd to reduce occurrences of negative results.
    
    ---
     GHC/Real.lhs |    2 +-
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    diff --git a/GHC/Real.lhs b/GHC/Real.lhs
    index 27b1b6c..f935151 100644
    a b x ^^ n = if n >= 0 then x^n else recip (x^(negate n)) 
    530530-- the result may be negative if one of the arguments is @'minBound'@ (and 
    531531-- necessarily is if the other is @0@ or @'minBound'@) for such types. 
    532532gcd             :: (Integral a) => a -> a -> a 
    533 gcd x y         =  gcd' (abs x) (abs y) 
     533gcd x y         =  abs (gcd' (abs x) (abs y)) 
    534534                   where gcd' a 0  =  a 
    535535                         gcd' a b  =  gcd' b (a `rem` b) 
    536536