[GHC] #6012: No warning for Incorrect display of 15! (factorial 15) when type is Int -> Int

GHC cvs-ghc at haskell.org
Tue Apr 17 08:31:44 CEST 2012


#6012: No warning for Incorrect display of 15! (factorial 15) when type is Int ->
Int
---------------------------------------+------------------------------------
    Reporter:  George.Atelier          |        Owner:                             
        Type:  bug                     |       Status:  closed                     
    Priority:  normal                  |    Component:  Compiler                   
     Version:  7.0.4                   |   Resolution:  invalid                    
    Keywords:  Int  Integer recursion  |           Os:  Windows                    
Architecture:  x86_64 (amd64)          |      Failure:  Incorrect result at runtime
    Testcase:  factorial 15            |    Blockedby:                             
    Blocking:                          |      Related:                             
---------------------------------------+------------------------------------
Changes (by dterei):

  * status:  new => closed
  * resolution:  => invalid


Comment:

 1) Calm down.

 2) Please check the Haskell language specification. Int is a bounded
 integer value guaranteed to be at least 30 bits long. The results of
 overflow are unspecified by the Haskell language specification and up to
 implementations to handle how they want. So GHC chooses to silently
 overflow.

 {{{
 The finite-precision integer type Int covers at least the range
 [  −  229, 229  −  1]. As Int is an instance of the Bounded class,
 maxBound and minBound can be used to determine the exact
 Int range defined by an implementation. Float is
 implementation-defined; it is desirable that this type be at least
 equal in range and precision to the IEEE single-precision type.
 Similarly, Double should cover IEEE double-precision. The
 results of exceptional conditions (such as overflow or underflow)
 on the fixed-precision numeric types are undefined; an
 implementation may choose error (⊥, semantically), a truncated
 value, or a special value such as infinity, indefinite, etc.
 }}}

 http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4

 3) Integer works as you expect as Integer is an unbounded integer value.
 So it will always be be big enough to represent the value you need.
 However this makes it a lot slower than an Int.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6012#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list