I just read an interesing blog post: http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308/. It seems that both the Java compiler and the Java runtime freeze when trying to convert the string “2.2250738585072012e-308″ to a double. Next to that, the bug seems quite old and still hasn’t been fixed. Being a .NET enthousiast, it was only natural for me to try this out on .NET and the C# compiler………

The Result:

I’ve used the following code:

—————————————————————————–

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(“Test:”);
            double d = Double.Parse(“2.2250738585072012e-308″);
            Console.WriteLine(d);
            Console.ReadKey();
        }
    }
}

———————————————————————————————-

Note that this wasn’t typed on my normal machine, so no fancy code plug-ins :). I am happy to announce that…………………………………………………………………………………

It just works as expected!! While I know that there must be bugs present in .Net that are not present in Java, I just thought this was worth a slight chuckle!

Have a nice weekend!!

 

This entry was posted in Various and tagged , , by Alex van Beek. Bookmark the permalink.
Alex van Beek

About Alex van Beek

Alex van Beek is oud-medewerker van Info Support. Zijn blogposts zijn dan ook gesloten voor comments.

5 thoughts on “C# and .NET don’t freeze when converting 2.2250738585072012e-308

  1. This bug doesn’t “freeze the runtime” (the whole VM) but the thread trying to parse that double. Just a minor nitpick :-)