Opened 3 months ago

Closed 3 months ago

Last modified 2 months ago

#8726 closed bug (fixed)

integer-gmp division regression

Reported by: erikd Owned by: hvr
Priority: highest Milestone: 7.8.1
Component: libraries (other) Version: 7.8.1-rc1
Keywords: integer-gmp Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty: Unknown
Test Case: numeric/should_run/T8726 Blocked By:
Blocking: Related Tickets: #8647

Description

With ghc 7.6.3:

ghci> quotRem 0x10000000000000001 (-0x100000)
(-17592186044416,1)
ghci> quotRem 0x10000001 (-0x100000)
(-256,1)

with ghc 7.7

ghci> quotRem 0x10000000000000001 (-0x100000)
(-17592186044416,-1)
ghci> quotRem 0x10000001 (-0x100000)
(-256,1)

Change History (6)

comment:1 Changed 3 months ago by hvr

  • Keywords Integer-gmp added; Integer removed
  • Owner set to hvr
  • Priority changed from normal to highest
  • Version changed from 7.7 to 7.8.1-rc1

comment:2 Changed 3 months ago by erikd

Related problems with divMod. ghc-7.6.3:

Prelude> divMod 0x10000000000000001 (-0x100000)
(-17592186044417,-1048575)
Prelude> divMod 0x10000000001 (-0x100000)
(-1048577,-1048575)

With ghc-7.7:

Prelude> divMod 0x10000000000000001 (-0x100000)
(17592186044417,1048575)
Prelude> divMod 0x10000000001 (-0x100000)
(-1048577,-1048575)
Last edited 3 months ago by erikd (previous) (diff)

comment:3 Changed 3 months ago by Herbert Valerio Riedel <hvr@…>

In 5f64b2c6e8f1799d7015098598f7d6e826707e6c/ghc:

Add test-case for #8726

This tests various properties expected to hold for
quotRem, divMod, div, mod, quot, and rem.

Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>

comment:4 Changed 3 months ago by Herbert Valerio Riedel <hvr@…>

In 2f841fdf5b33c4eb32cfc5d1b8207585f1880d9a/integer-gmp:

Fix negation of `divMod`/`quotRem` results (fixes #8726)

High-level pseudo code of what the code was supposed to implement:

    quotRem' :: Integer -> Integer -> (Integer,Integer)
    quotRem' a b@(S# _)
      | b < 0     = negFst . uncurry quotRem' . negSnd $ (a,b)
      | otherwise = quotRemUI a (fromIntegral (abs b))

    divMod' :: Integer -> Integer -> (Integer,Integer)
    divMod' a b@(S# _)
      | b < 0      = negSnd . uncurry divMod' . negBoth $ (a,b)
      | otherwise  = divModUI a (fromIntegral b)

    negFst  (q,r) = (-q,r)
    negSnd  (q,r) = ( q,-r)
    negBoth (q,r) = (-q,-r)

    -- quotRemUI and divModUI represent GMP's `mpz_{f,t}div_qr_ui()`
    quotRemUI, divModUI :: Integer -> Word -> (Integer,Integer)

Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>

comment:5 Changed 3 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from new to closed

Merged to HEAD/7.8 by Herbert.

comment:6 Changed 2 months ago by hvr

  • Keywords integer-gmp added; Integer-gmp removed
  • Test Case set to numeric/should_run/T8726
Note: See TracTickets for help on using tickets.