possible bug
John Mann
johnmann31416@yahoo.com
Sun, 22 Jun 2003 14:26:00 -0700 (PDT)
Hello all. I am writing a simple program to compute
pi, using the well-known and inefficient series:
pi ~= 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ...
and the program is:
pie :: Int -> Double
pie n
| n==1 = 4
| n==1005 = 2/fromInt n - 4/(fromInt n - 2) +
pie(n-4)
| otherwise = pie(n-4) + 4/fromInt n - 4/(fromInt
n - 2)
and this gives, using Hugs Version November 2002,
Main> pie 1005
3.14159
Now, if I change the number of terms to be about 10
times as many, by changing the program to:
pie :: Int -> Double
pie n
| n==1 = 4
| n==10005 = 2/fromInt n - 4/(fromInt n - 2) +
pie(n-4)
| otherwise = pie(n-4) + 4/fromInt n - 4/(fromInt
n - 2)
I get the LESS-accurate result:
Main> pie 10005
3.1416
This would seem to be a bug, but I am not sending it
to the bug list in case I'm doing something wrong with
Haskell or Hugs, or am mistaken with my program. Any
comments? Thanks.
John Mann
=====
"I'd rather be debugging...." - Anon
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com