Wednesday, February 2, 2011

Java Hangs When Converting 2.2250738585072012e-308 - link

Some guy discovered that JAVA JRE/JDK hangs when converting 2.2250738585072012e-308 number.

class runhang {
public static void main(String[] args) {
  System.out.println("Test:");
  double d = Double.parseDouble("2.2250738585072012e-308");
  System.out.println("Value: " + d);
 }
}

class compilehang {
public static void main(String[] args) {
  double d = 2.2250738585072012e-308;
  System.out.println("Value: " + d);
 }
}

PHP interpreter has the same bug.

<?php $d = 2.2250738585072011e-308; ?>

I have test and it seems that this number has no effect on .NET framework tried (NET frameworks 2.0-4.0).

namespace FloatingDecimal
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Test:");
            double d1;
            Double.TryParse("2.2250738585072012e-308", out d1);
            double d = 2.2250738585072012e-308;
            Console.WriteLine("Value: " + d + " other: " + d1);
        }
    }
}

Python interpreter is not effected too (tried version 3.1.1).

>>> d = 2.2250738585072012e-308
>>> d
2.2250738585072014e-308
>>> d = float("2.2250738585072012e-308")
>>> d
2.2250738585072014e-308

UPDATE:

Jython is effected...