summaryrefslogtreecommitdiff
path: root/testsuite/tests/unboxedsums/unboxedsums2.hs
blob: 115415f7c69ea0a5a7d63137c8aa2b35efb15cf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE UnboxedSums, MagicHash, BangPatterns #-}

module Main where

import GHC.Prim
import GHC.Types

-- Code generator used to fail with illegal instruction errors when Float# is
-- involved.

toInt :: (# Int# | Float# #) -> Int#
toInt (# i | #) = i
toInt (# | f #) = let !(I# i) = ceiling (F# f) in i

toFloat :: (# Int# | Float# #) -> Float#
toFloat (# i | #) = let !(F# f) = fromIntegral (I# i) in f
toFloat (# | f #) = f

data D = D { f1 :: (# Int# | Float# #) }

instance Show D where
  show (D (# i | #)) = "D " ++ show (I# i)
  show (D (# | f #)) = "D " ++ show (F# f)

main :: IO ()
main = do
    !(F# f) <- readLn
    print (I# (toInt (# | f #)))

    !(I# i) <- readLn
    print (F# (toFloat (# i | #)))

    print (D (# | f #))
    print (D (# i | #))