We all know that the Euler’s Number or Constant can be expressed this way,

And its value is around:

2.71828

Since the .NET C# double type supports Infinity now, both positive and negative which look great, let’s figure it out programmatically with the C# computer language as follows.

double positiveInfinity = double.PositiveInfinity;

double eulersConstant = Math.Pow((1 + 1 / positiveInfinity), positiveInfinity);

System.Windows.Forms.MessageBox.Show(string.Format("Euler's Constant = {0} ", eulersConstant));

What will the code yield?

It is, however, out of expectations of people with a bit math sense.

What do you think about it?

Hmm...

Remember infinity is just an idea not a real number. The reason C# have included it here is for range checking when the result is outside maxvalue or for a result when there is a 1/0 calculation instead giving an error.

1 divided by a very large number (ie infinity) approaches 0 but does not equal 0 which is why we use the limit notation because its impossible to accurately define the right answer.

On this basis the compiler should not allow you to use it the way you have.

Posted by: Doozer | 07/09/2012 at 06:16 AM

We all know that the INFINITY represents the idea of ENDLESS. The point here is that since its concept has been introduced into C# and most simple rules are made correct there too, e.g,

num + (positive) infinity = (positive) infinity; (positive) infinity + (positive) infinity = (positive) infinity; (postivie) infinity * (positivie) infinity = (positive) infinity; - ( PositiveInfinity) = NegativeInfinity; and so on

why the Euler's Number cann't be reached the way as expressed here?

It's like the computer can give us correctly some simple math calculations as n+n=2n, n-n=0, -(n) = -n but cannot give us a good result for complex ones such as (n+1/n)^m, isn't it?

If the computer cannot allow us to represent limit notation at all, what is the INFINITY really about? It's a number divided by something which is approaching to zero as you cited, isn't it?

If C# just throws out an exception about 1.0/0.0, it would be much easier for people to accept; if it equals to INFINITY but we cannot get the Euler's Number using the correct INFINITY (or Limit Notation) expression it would look obviously something wrong or missed out.

Posted by: Spiderinnet1 | 07/09/2012 at 05:21 PM

This is not something specific to c#. The infinity definition is set out in the IEEE 754 floating point standard. It states n/infinity = 0 hence the reason your calculation does not work. As mentioned it exists to provide a method of dealing with programming traps caused by how the computer represents floating numbers.

Posted by: Doozer | 07/09/2012 at 07:33 PM

I am not saying the IEEE should not have introduced in the INFINITY concept and n/INFINITY itself alone should not be equal to 0. It's about how C# implements it, good or bad, something simple already there and complex stuffs missed out.

BTW, what's the exact point of implementing n/0.0 as INFINITY and some simple rules but leaving the very useful Euler's Number calculation wrong?

It just seems to me that C# is not good for math calculations at all. That explains why some other computer languages are there for scientific calculations. If you check at what Sin(PI/2) and Cos(PI/2) in C# will give you respectively, you would know what I meant.

Posted by: Spiderinnet1 | 07/09/2012 at 09:27 PM

The issue is very interesting and complex and delves right into the heart of computer science. To get a full understanding read this (there is a section on infinity):

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Just to say there is no computer language in the world that will correctly compute the formula shown in your post. It can only be solved by approximation (ie using increasingly large numbers for n until the answers begin to see the numbers converge on an answer - 100,1000, 1000000 etc). Of course you could program a 'limit notation' function to do it but this is very different from actually being able to solve the formula as you show it.

Posted by: Doozer | 07/10/2012 at 11:17 AM

Thanks for the link. It’s a wonderful article written by a real expert and scientist. There is a lot info there to digest. I have bookmarked the page. Apparently Sun/Oracle does much better work about this than Microsoft, but better not always win as we know. In fact, better lose most of times.

Once again, not saying that IEEE should not have introduced all these useful concepts. The point is about how to implement/execute these especially by powerful parties. Bringing some fancy ideas into front to show I am the lead but leaving hard work to others to sort out does not look good. What about making Sin(PI/2) and Cos(PI/2) more consistent and accurate which are much more important in the calculation world? I know the PI cannot be perfectly represented by computer but a lot of algorithms there can improve the results as far as PI is concerned, but those who lead us either might just not want or are not capable to solve subtle issues like this to make our life easier instead of more confused.

Thank you again for trying hard to interpret all these.

Posted by: Spiderinnet1 | 07/10/2012 at 06:54 PM