[GHC] #1042: Floating point exception
GHC
ghc-devs at haskell.org
Sun Sep 21 03:28:58 UTC 2014
#1042: Floating point exception
-------------------------------------+-------------------------------------
Reporter: dons | Owner:
Type: merge | Status: new
Priority: normal | Milestone: 6.6.1
Component: Compiler | Version: 6.6
Resolution: | Keywords:
Operating System: | Architecture: x86
Unknown/Multiple | Difficulty: Unknown
Type of failure: Incorrect | Blocked By:
result at runtime | Related Tickets: #8695
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Changes (by dfeuer):
* owner: igloo =>
* status: closed => new
* resolution: fixed =>
Comment:
I'm sorry to reopen an 8 year old bug, but I tripped over this today while
attempting (unsuccessfully, so far) to write a version of `divModInt` that
plays nice with CSE:
{{{#!hs
divModInt :: Int -> Int -> (Int, Int)
(I# x) `divModInt` (I# y) = case x `divModInt#` y of
(# q, r #) -> (I# q, I# r)
divModInt# :: Int# -> Int# -> (# Int#, Int# #)
x# `divModInt#` y# = case x' `quotRemInt#` y# of
(# q, r #) -> (# q +# qadj, r +# radj #)
where
(# x', qadj, radj #) = if
| isTrue# (x# ># 0#) && isTrue# (y# <# 0#) -> (# x# -# 1#, -1#, y#
+# 1# #)
| isTrue# (x# <# 0#) && isTrue# (y# ># 0#) -> (# x# +# 1#, -1#, y#
-# 1# #)
| otherwise -> (# x#, 0#, 0# #)
}}}
When I test this with
{{{#!hs
main = print $ divModInt minBound (-1)
}}}
I get a floating point exception. `GHC.Base.divMod` does not trip over
this, even though it seems to be doing exactly the same arithmetic. As far
as I can tell, this is ''supposed'' to be handled by `quotRemInt#`
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/1042#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list