So I've been trying to figure this out for a good minutes, however all my attempts oddly result in infinity. What I'm trying to do is calculate pi and e to a certain level(or limit as I put it).
Which confuses me.. But I was wondering if anyone here could help shed some light on the matter.
This is what I have, and both produce "infinity"
vbnet Code:
Public ReadOnly Property e(ByVal Optional limit As Int32 = 10) As Double Get Dim result As Double For i As Int32 = 0 to limit result= result + 1/i Next Return result End Get End Property Public ReadOnly Property Pi(ByVal Optional limit As Int32 = 2) As Double Get 'Pi = (6(1/1^2 + 1/2^2 + 1/3^2 + 1/4^2 + ...))^(1/2) Dim tmp As Double = 0 For i As Int32 = 0 To limit tmp = tmp + (1/i)^2 Next Return (6*tmp)^(1/2) End Get End Property
NOTE: I know someone will say "oh why don't you just use a constant?" Well that's because I don't want to. I'd rather have something that can produce pi to a certain length(limit), depending on which use for pi is being used.
Honestly I'm not even sure why this occurs, but perhaps it's the limit of the double value that I'm maxing? Which if it was then I'd suspect an exception would have been thrown rather than producing infinity..





Reply With Quote