[ ghc-Bugs-652927 ] Integer -> Int64 sometimes wrong
noreply at sourceforge.net
noreply at sourceforge.net
Fri Dec 13 09:26:21 EST 2002
Bugs item #652927, was opened at 2002-12-12 21:24
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=652927&group_id=8032
Category: hslibs/lang
Group: 5.04.2
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Mike Gunter (magunter)
>Assigned to: Simon Marlow (simonmar)
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
----------------------------------------------------------------------
>Comment By: Simon Marlow (simonmar)
Date: 2002-12-13 14:26
Message:
Logged In: YES
user_id=48280
Fixed; thanks.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=652927&group_id=8032
More information about the Glasgow-haskell-bugs
mailing list