Ticket #1517: demo.hs

File demo.hs, 517 bytes (added by dbenbenn@…, 7 years ago)

Examples of overflow bugs

Line 
1import Data.Int
2import Ratio
3
4a = 1 % (2 :: Int32)
5c = 1616076535 % (430549561 :: Int32)
6
7main = do
8        putStrLn ("Should be True: " ++ show (a < c))
9        putStrLn ("Should be 1%42: " ++ show (fromRational (-3 % 130) :: Ratio Int8))
10        putStrLn ("Should be 127%1: " ++ show (127%(2::Int8) + (127%(2::Int8))))
11        putStrLn ("Should be 127%1: " ++ show (127%(2::Int8) - (-127%(2::Int8))))
12        putStrLn ("Should be 75%1: " ++ show (125%(1::Int8) * (3%(5::Int8))))
13        putStrLn ("Should be 75%1: " ++ show (125%(1::Int8) / (5%(3::Int8))))