Value range of Float in Java

xiaoxiao2021-03-06  113

Specifications indicate that the floating point in Java is used in the IEEE Standard 754 Floating Point Numbers standard, the standard specification can be referred to http://blog.9cbs.net/treeroot/articles/94752.aspx. Float occupies 4 bytes, Like Int, that is, 32bit. 1st bit represents symbols, 0 indicates positive numbers, 1 indicates negative numbers, this is very well understood, no multi-tube. 2-9 bits Represents an index, a total of 8 bits (can represent 0 -255) The base is 2, in order to simultaneously represent positive and negative numbers, the amount of 127 is subtracted. In this way, the scope is (-127 to 128), and the other 0 and all 1 are specially treated, so Directly represented -126 to 127. The remaining 23 represents the fractional portion, where 23 represents a 24-bit number, because there is a default leading 1 (this characteristics only). The last result is: (- 1) ^ (Sign) * 1.F * 2 ^ (Exponent) Here: Sign is the symbol bit, F is the score of 23 bit, the exponent is the index portion, and finally the scope is (because the number of positive and negative is symmetrical, here only cares Number 2 ^ (- 126) ~~ 2 (1-2 ^ (- 24)) * 2 ^ 127 This is not the value range of FLOAT, because the standard is also specified in the non-specific representation, and there are some Special provisions. Non-specificity indicates that the index part is 0 and the decimal floating point number is indicated when the decimal portion is 0, because the default is not a preamble 1, but 0.5. 取 值 0.f * 2 ^ (- 126 ), The scope is 2 ^ (- 149) ~~ (1-2 ^ (- 23)) * 2 ^ (- 126) Nothing here. Why is -126 instead of -127? If it is -127 Then, the maximum is 2 ^ (- 127) -2 ^ (- 149), it is obvious that 2 ^ (- 127) ~~ 2 ^ (- 126) cannot be expressed.

Other Special Representation 1. When the index portion and the decimal portion are all 0, the 0 value, the 0 and -0 points (symbolic decision), 0x00000000 represents the 0,0x80000000 represents the negative 0. 2. Index part all 1 When the decimal part is all 0, it means infinity, there is endless and negative, 0x7f800000 indicates that the 0xFF800000 is endless. 3. The index part is 1, the decimal part is 0, indicating nan, divided into QNAN and SNAN, Java All are Nan. Conclusion It can be seen that the value of the floating point number is: 2 ^ (- 149) ~~ (2-2 ^ (- 23)) * 2 ^ 127, that is, float.min_value and float.max_value.

转载请注明原文地址:https://www.9cbs.com/read-97510.html

New Post(0)