Commit ac5afe0c authored by Simon Marlow's avatar Simon Marlow
Browse files

Fix num012 on 32-bit platforms

round and truncate are undefined if the result would be outside
the range of the target type (#1254).
parent e94c75ae
......@@ -2,20 +2,28 @@
-- Test for trac #921
import GHC.Float
import Foreign
import Control.Monad
main :: IO ()
main = do -- The reported case
putStrLn (show (map log2 vals))
-- Smaller failing cases
print (fromIntegral ((2^31) :: Int) :: Double)
print (round ((2^33) :: Double) :: Int)
if_not_32 $ print (round ((2^33) :: Double) :: Int)
print (fromIntegral ((2^31) :: Int) :: Float)
print (round ((2^33) :: Float) :: Int)
if_not_32 $ print (round ((2^33) :: Float) :: Int)
-- The underlying failing internal operations
print (int2Double (2^31))
print (double2Int (2^33))
if_not_32 $ print (double2Int (2^33))
print (int2Float (2^31))
print (float2Int (2^33))
if_not_32 $ print (float2Int (2^33))
where
-- the value of float2Int x where the result would be outside the
-- range of the target is undefined. We also take the view in GHC
-- that round and truncate are similarly undefined when the result
-- would be outside the range of the target type (see #1254)
if_not_32 = when (sizeOf (undefined::Int) > 4)
log2 x = ceiling log_x
where log_x :: Double
......
[0,1,5,9,10,14,31,31,32,32,32,32,33]
-2.147483648e9
0
-2.1474837e9
0
-2.147483648e9
2147483647
-2.1474837e9
2147483647
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment