One. Double type store indicates that the floating point type of Java is fully in accordance with the IEEE754 standard (Standards of IEEE 754 FLOATING POINT NUMBERS), is interested in IEEE Standard Website (www.ieee.org). The content is basically described STORGE LAYOUT, STORGE LAYOUT, below, to summarize this standard, please refer to the standard original. 1. What is a floating point. The real number of expressions on the computer is two methods: fixed point representation ( FLOATING-POINT. The fixed point representation is that a certain position in the middle of the existing numbers, the representation of the integer part and the decimal part and a normal integer representation. For example, Our number is 4, the decimal point is in the middle, then you can represent 10.28, or it can also indicate 00.01, similar to the nature of this method indicating that there is also the form of the score. The fixed window form of the fixed point makes him not to represent Very large number can't represent very small number. And when the division occurs, a large amount of accuracy is lost. The floating point number uses a scientific counting method to represent the real number. For example, 123.456 can be expressed as 1.23456 × 102. Fix to the fixed point Fixed window restrictions, it is a floating window, so it can represent a real number of larger precision ranges. 2. Storage layout so-called storage layout is how a floating point number is in memory Said. We know that the floating point has float and double, the former is 32 bytes, the latter is 8 bytes is 64. The layout is:
Symbol index fractional partial offset Additional (BIAS) single precision 1 [31] 8 [30-23] 23 [22-00] 127 Dual Accuracy 1 [63] 11 [62-52] 52 [51-00] 1023
In the brackets, the number range is bits, the number of bits possessed outside. Offset attachment does not belong to the content represented, is a constant, explained later. The symbol is only one: 0- indicates positive number 1- Indicates a negative index portion: Diming the value of the value of the index portion (8-bit / 11 bit, unsigned) to add the actual index, for example, 200-127, the actual index is 73 = 200-127. For bisponic Double Constant Bias = 1023 Malid: What is the mantissa? For a scientific counting method, the form is like such a LM × BE, then this LM is the so-called mantissa. It consists of a starting position and a fractional part Composition. For example, 5 can be expressed as different forms: 5 * 100 0.5 * 101 50 * 10-1, then we introduce a concept, normalized form, and Denormalized Form. We Defining the decimalized form is a decimal form in the form of a decimal form, so the first form of the above is in a normalized form, and other non-standardized forms, floating point in Java is fully followed. There are only two forms of standardized form: 1.F and non-standardized form 0.F. So, for our position layout, choose the base of 2, only one number is non-zero, that is 1. So we hidden The starting number can not take one bit, because in addition to 0, it can only be 1, the specific implicit rules, demonstrated. 3. Significance. Corresponding to the above table, each area corresponding to the value of each area The meaning of the floating point representation: Symbol bit S Inditable Bit E Number F, the meaning V 0 00..00 00..00 0 00 00..01: 11..11 positive non-specific Real, calculation method v = 0.F × 2 (-b 1) 0 00..01: 11..10 XX..xx positive standardized real number, calculation method V = 1.f × 2 (EB) 0 11 ..11 00..00 infinite 0 11..11 ..01: 01..11 meaningless non-digital Snan 0 11..11 10..00: 11..11 meaningless non-numeric QNAN where b = 127 (float) / b = 1023 (double), SNAN indicates invalid operation results, and QNAN means that uncertain operation results are meaningless. If the symbolite S Change to 1, then all is negative, other meaning and this same.
In addition, we have seen that for meaningless numbers are all 1 when the index is all 1, that is, there are many combinations here, and our Java, it is quite simple to determine if a number is nan. Static public boolean isnan (v! = v);} From here you can see that the virtual machine is compared to the Double type data, it must be a judgment of the index value first, and found not all when Memory's bitmap comparison. Of course, this is what I have to speculate, I don't know if it is.
Further, we're very clear, the minimum value that the double type can be expressed is the distance between its values, that is, the accuracy of what we said, the number is integrated into an integer "1 steps, just You can't match 1, in other words, 1 is not a minimum (accuracy / distance) integer multiple. So if you set the variable double d = 0.1; and the result will not be 0.1, because you can't represent 0.1;
II. How to view the Double type storage structure? We are very clear that Java's Double Type provides a function called DoubleTolongBits function. This function is actually very simple. We know that long types and double types are 64-bit, their memory size is the same. The function of this function is to copy the memory structure corresponding to the Double to the memory structure of the same size for the LONG type variable. Return to this long value. Because Java does not support the Double type operation, it is: 1. This function is impossible The Java language is completed, so he is a JNI implementation 2. We use the bit calculation for the long type to print out. / ** * Test * / public static void main (String [] args) {MyTest T = New mytest (); double d = 0.1d; long l = double.douBletolongbits (d); system.out.println (t.getlongbits (l));} / ** * Get normal bit bit represents string * @ Param a * @return * / public string getlongbits (long a) {// 8 byte arrays, read out byte [] b = new byte [8]; for (int i = 7; i> = 0 i -) {b [i] = (byte) (a & 0x000000FF); a = a >> 8;} return this.byte2hex (b); // Call the following function} / ** * byte array conversion to String * @Param B * @return * / public static string Byte2HEX (byte [] b) {stringbuffer sb = new stringbuffer (); string stmp = ""; for (int N = 0; n We recover and the representation of the first quarter is controlled in the table: 01111111011 1001 ..... 1010 If you are interested, you can calculate its value according to the rules of the first quarter, oh, it is the result of our printed through System.out.Println (d). Ok. This is all, I don't think I know very clearly, because my always feel that the text is still a little distance, probably this is expressive. If you don't arrogate, I will be very happy. . Cao Xihua is completed in 2005-3-27 15:38:25