Ticket #4321: Pi.hs

File Pi.hs, 427 bytes (added by bjpop, 4 years ago)

Source code of Haskell program which induces bug

Line 
1module Main where
2
3import Control.Applicative ((<$>))
4import System (getArgs)
5
6main :: IO ()
7main = do
8   n <- read <$> head <$> getArgs
9   print $ integrate n (1 / fromIntegral n)
10
11integrate :: Int -> Double -> Double
12integrate n h =
13   -- h * ((sum (map area [1..n])) :: Double)
14   h * (sum (map area [1..n]))
15   where
16   area :: Int -> Double
17   area i
18      = 4 / (1 + x*x)
19      where
20      x = h * (fromIntegral i - 0.5)