|
[ ghc-Bugs-652863 ] Integer -> Int64 sometimes wrong: msg#00026lang.haskell.glasgow.bugs
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: Closed >Resolution: Duplicate 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> |
|---|---|---|
| Previous by Date: | [ ghc-Bugs-648783 ] Compile error for HsNet.h, noreply |
|---|---|
| Next by Date: | [ ghc-Bugs-653009 ] com. line args not honoured for recompil, noreply |
| Previous by Thread: | [ ghc-Bugs-652863 ] Integer -> Int64 sometimes wrong, noreply |
| Next by Thread: | [ ghc-Bugs-652927 ] Integer -> Int64 sometimes wrong, noreply |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |