logo       

[ ghc-Bugs-652863 ] Integer -> Int64 sometimes wrong: msg#00020

lang.haskell.glasgow.bugs

Subject: [ ghc-Bugs-652863 ] Integer -> Int64 sometimes wrong

Bugs item #652863, was opened at 2002-12-12 20:02
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=652863&group_id=8032

Category: hslibs/lang
Group: 5.04.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Mike Gunter (magunter)
Assigned to: Nobody/Anonymous (nobody)
Summary: Integer -> Int64 sometimes wrong

Initial Comment:
Conversion from Integer to Int64 values sometimes
produces the wrong
value. In particular, it seems to fail on
small-magnitude negative
values whose representation is large. E.g.

> (fromIntegral ((2^30 -1 + 2^30) - (2^30 + 2^30 ::
Integer))) :: Data.Int.Int64
4294967295
> (fromIntegral ((2^30 - 2 + 2^30) - (2^30 - 1 + 2^30
:: Integer))) :: Data.Int.Int64
-1

The Haskell-level workaround is to do the conversion as
a non-negative
number then negate if needed:

> let fis (i::Integer) = (fromIntegral (signum i) *
fromIntegral (abs i)) :: Data.Int.Int64
> fis ((2^30 -1 + 2^30) - (2^30 + 2^30 :: Integer))
-1


----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=652863&group_id=8032


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise