
Here's what i got writeln x = putStr (x++ "\n") f:: Double -> IO Double f x = do let t = 2*x if (t<1) then return t else return (t-1) gen :: Double -> IO() gen x = do c<-f x writeln ("Value is: " ++ show c) if (c /= 0.0) then gen c else return () Main> gen 0.1 Value is: 0.2 Value is: 0.4 Value is: 0.8 Value is: 0.6 Value is: 0.2 Value is: 0.4 Value is: 0.800000000000001 Value is: 0.600000000000001 Value is: 0.200000000000003 Value is: 0.400000000000006 Value is: 0.800000000000011 Value is: 0.600000000000023 Value is: 0.200000000000045 Value is: 0.400000000000091 Value is: 0.800000000000182 Value is: 0.600000000000364 Value is: 0.200000000000728 Value is: 0.400000000001455 Value is: 0.80000000000291 Value is: 0.600000000005821 Value is: 0.200000000011642 Value is: 0.400000000023283 Value is: 0.800000000046566 Value is: 0.600000000093132 Value is: 0.200000000186265 Value is: 0.400000000372529 Value is: 0.800000000745058 Value is: 0.600000001490116 Value is: 0.200000002980232 Value is: 0.400000005960464 Value is: 0.800000011920929 Value is: 0.600000023841858 Value is: 0.200000047683716 Value is: 0.400000095367432 Value is: 0.800000190734863 Value is: 0.600000381469727 Value is: 0.200000762939453 Value is: 0.400001525878906 Value is: 0.800003051757813 Value is: 0.600006103515625 Value is: 0.20001220703125 Value is: 0.4000244140625 Value is: 0.800048828125 Value is: 0.60009765625 Value is: 0.2001953125 Value is: 0.400390625 Value is: 0.80078125 Value is: 0.6015625 Value is: 0.203125 Value is: 0.40625 Value is: 0.8125 Value is: 0.625 Value is: 0.25 Value is: 0.5 Value is: 0.0
From: Cale Gibbard
Reply-To: Cale Gibbard To: Dinh Tien Tuan Anh CC: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Error with Float Date: Tue, 19 Jul 2005 11:00:34 -0400 Perhaps you mean: f x | x < 1 = 0 : f (2*x) | otherwise = 1 : f (2*(x-1))
Note that in the second case, the 1 is subtracted before multiplication by 2.
If you were referring to the problem that this eventually gives constantly 0 for values like 0.6, try importing the Ratio module and applying it to 6%10, which is the exact rational value rather than a floating point representation.
- Cale
_________________________________________________________________ Winks & nudges are here - download MSN Messenger 7.0 today! http://messenger.msn.co.uk