Wednesday, April 18, 2012

2.2250738585072012e- 308





2. 2250738585072012e - 308.



At this parser including a double- looped numbers in Java. For example the line ... double d = 2. 2250738585072012e -308;. ... They can also break the already running applications ( if they read Doubles ). Interesting commentators of the original article (see. below) is outraged at the Google - dock, writing a number in a table cell.



Java crashes on 2. 2250738585072012e -308 ( Habr ).


source:.
http://habrahabr. ru/blogs/java/112948.

Constantine Praysser (. Konstantin Preisser. ) Recently discovered something very interesting: Java - the compiler and the runtime - enters an infinite loop when converting decimal. 2. 2250738585072012e - 308. in double. The idea is that the number should be converted to. 0x1p- 1022. That is,. Double. MIN_VALUE. However, Java hangs on. 0x0. fffffffffffffp- 1022. , The largest. denormalized number. for double.



An infinite loop at runtime.




class RuntimeHang {. 
public static void main (String [] args) {.
System. out. println ('Test:');.
double d = Double. parseDouble ('2. 2250738585072012e -308 ');.
System. out. println ('Value:' d);.
}.
}.




An infinite loop at compile time.



(. If you want to try it in Eclipse, be sure to save everything first, and then the shadow of his compilation and knew it did not have time to. - a comment. Trans. ).

class CompilationHang {. 
public static void main (String [] args) {.
double d = 2. 2250738585072012e -308;.
System. out. println ('Value:' d);.
}.
}.


Under the cut 's arguments about the causes of this phenomenon.



What's the matter?.



Constantine found that at least in the runtime problem lies in the ...
FloatingDecimal. java. He writes:.



If you comment out this part, the runtime is no longer hang as. Double. parseDouble (String s). That causes. sun. misc. FloatingDecimal. readJavaFormatString (s). doubleValue (). - Code clean java, no native. But there used artifmetika floating point numbers, so that it can be configured kompilyarota, which compiled the JRE and javac.

Without the correction cycle out those bits (big endian):.

00000000 00001111 11111111 11111111 11111111 11111111 11111111 11111111. 


That is, the number is converted into the largest denormalized floating-point number, because the exponent is zero. Without the correction cycle the same thing happens with. 2. 2250738585072013e - 308. But if the cycle is uncommented, then convert correctly:.

00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000. 

No comments:

Post a Comment