#4108: GHC.Integer.hashInteger is a misnomer and confuses people
---------------------------+------------------------------------------------
  Reporter:  duncan        |          Owner:                  
      Type:  bug           |         Status:  new             
  Priority:  normal        |      Milestone:  6.14.1          
 Component:  Compiler      |        Version:  6.12.2          
Resolution:                |       Keywords:                  
Difficulty:                |             Os:  Unknown/Multiple
  Testcase:                |   Architecture:  Unknown/Multiple
   Failure:  None/Unknown  |  
---------------------------+------------------------------------------------

Comment(by simonmar):

 I just took a look at this, and I think 'hashInteger' is actually wrong:

 {{{
 hashInteger :: Integer -> Int#
 hashInteger (S# i) = i
 hashInteger (J# s d) = if s ==# 0#
                        then 0#
                        else indexIntArray# d 0#
 }}}

 Suppose the `Integer` is `-j` for some `j` and fits in `Int#`.  If the
 representation is `S#` then `hashInteger` returns `-j`, but if the
 representation is `J#` then `hashInteger` returns `j`.  We don't guarantee
 to represent an `Integer` using `S#` if it fits in an `Int#`, so I think
 this is wrong.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4108#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to