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:
  1. Public ReadOnly Property e(ByVal Optional limit As Int32 = 10) As Double
  2.         Get
  3.             Dim result As Double
  4.  
  5.             For i As Int32 = 0 to limit
  6.                 result= result + 1/i
  7.             Next
  8.             Return result
  9.         End Get
  10.     End Property
  11.  
  12.     Public ReadOnly Property Pi(ByVal Optional limit As Int32 = 2) As Double
  13.         Get
  14.             'Pi = (6(1/1^2 + 1/2^2 + 1/3^2 + 1/4^2 + ...))^(1/2)
  15.             Dim tmp As Double = 0
  16.  
  17.             For i As Int32 = 0 To limit
  18.                 tmp = tmp + (1/i)^2
  19.             Next
  20.             Return (6*tmp)^(1/2)
  21.         End Get
  22.     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..