[GHC] #14085: powModInteger sometimes ignores sign of argument

#14085: powModInteger sometimes ignores sign of argument -------------------------------------+------------------------------------- Reporter: ocheron | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Core | Version: 8.2.1 Libraries | Keywords: integer-gmp | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Function `intToSBigNat#` returns a `PosBN` result when input is < -1, but it should be `NegBN` instead. As a consequence functions like `powModInteger` give incorrect result for small negative numbers: {{{ $ ghci GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help
:m GHC.Integer.GMP.Internals powModInteger (-2) 3 123 8 (-2)^3 `mod` 123 115 }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14085 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14085: powModInteger sometimes ignores sign of argument -------------------------------------+------------------------------------- Reporter: ocheron | Owner: ocheron Type: bug | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 8.2.1 Resolution: | Keywords: integer-gmp Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3826 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ocheron): * owner: (none) => ocheron * failure: None/Unknown => Incorrect result at runtime * differential: => Phab:D3826 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14085#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14085: powModInteger sometimes ignores sign of argument -------------------------------------+------------------------------------- Reporter: ocheron | Owner: ocheron Type: bug | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 8.2.1 Resolution: | Keywords: integer-gmp Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3826 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ocheron): Working on a patch I found another issue with `gcdExtInteger` when first argument is negative. Program: {{{#!haskell {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} import GHC.Integer.GMP.Internals f a b = let (# g, s #) = gcdExtInteger a b in (g, s) main = do print $ f 100000000000000000000000000000 7 print $ f (-100000000000000000000000000000) 7 }}} crashes with assertion when executed: {{{ $ ghc -V && ghc --make a The Glorious Glasgow Haskell Compilation System, version 8.2.1 [1 of 1] Compiling Main ( a.hs, a.o ) Linking a ... $ ./a (1,3) Assertion failed: (sn <= xn), function integer_gmp_gcdext, file libraries /integer-gmp/cbits/wrappers.c, line 315. Abort trap: 6 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14085#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14085: powModInteger sometimes ignores sign of argument -------------------------------------+------------------------------------- Reporter: ocheron | Owner: ocheron Type: bug | Status: new Priority: normal | Milestone: Component: Core Libraries | Version: 8.2.1 Resolution: | Keywords: integer-gmp Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3826 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Nice catch and thanks for working on a fix. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14085#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14085: powModInteger sometimes ignores sign of argument
-------------------------------------+-------------------------------------
Reporter: ocheron | Owner: ocheron
Type: bug | Status: new
Priority: normal | Milestone:
Component: Core Libraries | Version: 8.2.1
Resolution: | Keywords: integer-gmp
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result | Unknown/Multiple
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3826
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#14085: powModInteger sometimes ignores sign of argument -------------------------------------+------------------------------------- Reporter: ocheron | Owner: ocheron Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Core Libraries | Version: 8.2.1 Resolution: fixed | Keywords: integer-gmp Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3826 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14085#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC