[VII] Float details of the underlying data type

Source: Internet
Author: User

Float basic data type float's wrapper class float type object contains a float type of field Introduction to Properties
The number of bits used to represent the float value in twos complement form public static final int SIZE = 32;
The number of bytes in the binary complement form that represents the float value public static final int BYTES = size/byte.size;
Class instance representing the base type float public static final class<float> TYPE = (class<float>) class.getprimitiveclass ("Float");
The maximum value that can be represented
Only one form of standardization, that is, mentioned earlier
public static final float max_value = 0x1.fffffep+127f;
Minimum value for normalization
public static final float min_normal = 0x1.0p-126f;
The minimum value is also non-standardized form
public static final float min_value = 0x0.000002p-126f;
Positive Infinity
It equals the value returned by Float.intbitstofloat (0x7f800000)
public static final float positive_infinity = 1.0f/0.0f;
Negative infinity
It equals the value returned by Float.intbitstofloat (0xff800000)
public static final float negative_infinity = -1.0f/0.0f;
NaN
Not a number
It equals the value returned by Float.intbitstofloat (0x7fc00000)
public static final float NaN = 0.0f/0.0f;
The effective maximum of the exponential truth value public static final int max_exponent = 127;
The effective minimum value of the exponential truth public static final int Min_exponent =-126;
These properties, read the previous floating point introduction, can be very clear understanding
Construction MethodFloat still provides a string form that is based on the basic type float and float, and is still aided by the Parsexxx form parsefloat In addition, it also provides a way to construct a double based on the basic type, with a direct strong internal
Float (float value)
Float (String s)
Float (Double value) Direct Strong turn
Common MethodsFor floating-point numbers, there are some additional property methods in our floating-point number introduction, for floating-point representation of the description of float provides a representation of the specified value of the acquisition method, which is the representation of a 32-bit bits sequence
Float Gets the representation
Provides two forms of methods for getting representations, mainly for different representations of non-numeric Nan
They can be converted to each other with intbitstofloat.

floattointbits If the parameter is positive infinity, the result is 0x7f800000 if the argument is negative infinity, the result is 0xff800000 if the argument is NaN, the result is 0x7fc00000   in all cases, the result It's all an integer. Assigning it to the intbitstofloat (int) method generates a floating-point value that is the same as the Floattointbits parameter (and all Nan values generate a specification NaN value)   Dependent floattorawintbits
Converts the representation to float, returning a float value corresponding to the positional representation
Local method
In fact, the float is calculated according to the layout


If the argument is 0x7f800000, the result is positive infinity if the argument is 0xff800000, the result is negative infinity if the parameter value is between 0x7f800001 to 0x7FFFFFFF or 0xff800001 to 0xFFFFFFFF, the result is NaN None of the IEEE 754 floating-point operations provided by Java can distinguish between two homogeneous Nan values with different bit patterns, and only use the Float.floattorawintbits method to differentiate between Nan values
There are several special representations of floating-point numbers, such as Infinite Nan, which also provide some related methods.
Static Boolean IsNaN (float v) Static methods
Whether a non-numeric (NaN) value
Non-numeric true
Static Boolean isfinite (float f) Static methods
Whether it is a limited floating-point number
Limited true
Static Boolean isinfinite (float v) Static methods
Whether it is infinity
Is infinitely large true
Boolean isinfinite () Instance method
Rely on static methods
Boolean IsNaN () Instance methods rely on static methods
Comparison
static int compare (float f1, float F2) Static methods
Comparison of two float
F1 < F2 less than 0
F1 = F2 equals 0
F1 > F2 greater than 0
int CompareTo (Float anotherfloat) Instance method
Two objects for size comparison, dependent on static methods
PARSEXXX series strings are parsed as basic types and do not require objects, so they are static methods
Returns a string representation of the base type of float
The performance is the same as valueof (String), but valueof returns the object
If string is null or does not contain a string that can be parsed, an exception will be thrown
Bottom-dependent sun.misc.FloatingDecimal


The ValueOf Series wraps the basic basic types as objects used to create the acquisition object, so no objects are required, all static methods are different from the integer values described earlier, they all have buffer float does not exist cache, valueof is also a direct new object
static float valueOf (float f)
Static Float valueOf (String s) Dependent parsefloat Method
So it says it works the same as valueof (String), which is the same thing.
Float No Decode method Xxxvalue Series
Similar to other numeric types described earlier
All of them are internal value of strong turn
Return (XXX) value;
Bytevalue () Shortvalue () Intvalue () Longvalue () Floatvalue () Doublevalue ()
toString toxxxstring Series
static String toString (float f)
string toString () Internal call   Static String toString (float f)
static String tohexstring (float f) Returns the hexadecimal string representation of the float parameter
The ToString series seems to have nothing to say, and it seems like there's a lot to be said about the rules of the format characters have doubts directly view APIequals
boolean equals (Object obj) &nbs P Compare this object to a specified object when and only if the parameter is not NULL but a Float object, and represents a float value that is the same as the float value represented by this object, the result is true if and only if the method #floatToLongBits (double) is applied to the value of the int returned by the two value, it is considered that the two float values are the same   attention, In most cases, the value of F1.equals (F2) is true for two instances of the Float class F1 and F2, when and only if the value of f1.floatvalue () = = F2.floatvalue () is true. However, there are two exceptions: if both F1 and F2 represent Float.nan, the False,equals method will return true even if the value of Float.nan==float.nan is used, so this is floattointbits instead of RA W   If F1 represents +0.0f, and F2 represents -0.0f, or vice versa, even 0.0f==-0.0f test will return FALSE if the value is true,equal the definition allows the hash table to operate correctly.
hashcode
static int hashcode (float value) Static methods
Get the hashcode value of a value
int Hashcode () Instance method
Rely on static methods
Other methods
sum (float, float)
Max (float, float)
Min (float, float)
SummaryIn fact, the expression of floating-point numbers and the use of norms is the focus of float is just float packaging, float is only a IEEE754 standard implementation, is still in the standard understanding

[VII] Float details of the underlying data type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.