| Method from java.lang.Float Detail: |
public byte byteValue() {
return (byte) value;
}
|
public static int compare(float float1,
float float2) {
// Non-zero, non-NaN checking.
if (float1 > float2) {
return 1;
}
if (float2 > float1) {
return -1;
}
if (float1 == float2 && 0.0f != float1) {
return 0;
}
// NaNs are equal to other NaNs and larger than any other float
if (isNaN(float1)) {
if (isNaN(float2)) {
return 0;
}
return 1;
} else if (isNaN(float2)) {
return -1;
}
// Deal with +0.0 and -0.0
int f1 = floatToRawIntBits(float1);
int f2 = floatToRawIntBits(float2);
// The below expression is equivalent to:
// (f1 == f2) ? 0 : (f1 < f2) ? -1 : 1
// because f1 and f2 are either 0 or Integer.MIN_VALUE
return (f1 > > 31) - (f2 > > 31);
}
Compares the two specified float values. There are two special cases:
- {@code Float.NaN} is equal to {@code Float.NaN} and it is greater
than any other float value, including {@code Float.POSITIVE_INFINITY};
- +0.0f is greater than -0.0f
|
public int compareTo(Float object) {
return compare(value, object.value);
}
Compares this object to the specified float object to determine their
relative order. There are two special cases:
- {@code Float.NaN} is equal to {@code Float.NaN} and it is greater
than any other float value, including {@code Float.POSITIVE_INFINITY};
- +0.0f is greater than -0.0f
|
public double doubleValue() {
return value;
}
|
public boolean equals(Object object) {
return (object == this)
|| (object instanceof Float)
&& (floatToIntBits(this.value) == floatToIntBits(((Float) object).value));
}
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, {@code object} must be an instance of
{@code Float} and have the same float value as this object. |
public static native int floatToIntBits(float value)
Converts the specified float value to a binary representation conforming
to the IEEE 754 floating-point single precision bit layout. All
Not-a-Number (NaN) values are converted to a single NaN
representation ({@code 0x7ff8000000000000L}). |
public static native int floatToRawIntBits(float value)
Converts the specified float value to a binary representation conforming
to the IEEE 754 floating-point single precision bit layout.
Not-a-Number (NaN) values are preserved. |
public float floatValue() {
return value;
}
Gets the primitive value of this float. |
public int hashCode() {
return floatToIntBits(value);
}
|
public static native float intBitsToFloat(int bits)
Converts the specified IEEE 754 floating-point single precision bit
pattern to a Java float value. |
public int intValue() {
return (int) value;
}
|
public boolean isInfinite() {
return isInfinite(value);
}
Indicates whether this object represents an infinite value. |
public static boolean isInfinite(float f) {
return (f == POSITIVE_INFINITY) || (f == NEGATIVE_INFINITY);
}
Indicates whether the specified float represents an infinite value. |
public boolean isNaN() {
return isNaN(value);
}
Indicates whether this object is a Not-a-Number (NaN) value. |
public static boolean isNaN(float f) {
return f != f;
}
Indicates whether the specified float is a Not-a-Number (NaN)
value. |
public long longValue() {
return (long) value;
}
|
public static float parseFloat(String string) throws NumberFormatException {
return org.apache.harmony.luni.util.FloatingPointParser
.parseFloat(string);
}
Parses the specified string as a float value. |
public short shortValue() {
return (short) value;
}
|
public static String toHexString(float f) {
/*
* Reference: http://en.wikipedia.org/wiki/IEEE_754
*/
if (f != f) {
return "NaN"; //$NON-NLS-1$
}
if (f == POSITIVE_INFINITY) {
return "Infinity"; //$NON-NLS-1$
}
if (f == NEGATIVE_INFINITY) {
return "-Infinity"; //$NON-NLS-1$
}
int bitValue = floatToIntBits(f);
boolean negative = (bitValue & 0x80000000) != 0;
// mask exponent bits and shift down
int exponent = (bitValue & 0x7f800000) > > > 23;
// mask significand bits and shift up
// significand is 23-bits, so we shift to treat it like 24-bits
int significand = (bitValue & 0x007FFFFF) < < 1;
if (exponent == 0 && significand == 0) {
return (negative ? "-0x0.0p0" : "0x0.0p0"); //$NON-NLS-1$ //$NON-NLS-2$
}
StringBuilder hexString = new StringBuilder(10);
if (negative) {
hexString.append("-0x"); //$NON-NLS-1$
} else {
hexString.append("0x"); //$NON-NLS-1$
}
if (exponent == 0) { // denormal (subnormal) value
hexString.append("0."); //$NON-NLS-1$
// significand is 23-bits, so there can be 6 hex digits
int fractionDigits = 6;
// remove trailing hex zeros, so Integer.toHexString() won't print
// them
while ((significand != 0) && ((significand & 0xF) == 0)) {
significand > > >= 4;
fractionDigits--;
}
// this assumes Integer.toHexString() returns lowercase characters
String hexSignificand = Integer.toHexString(significand);
// if there are digits left, then insert some '0' chars first
if (significand != 0 && fractionDigits > hexSignificand.length()) {
int digitDiff = fractionDigits - hexSignificand.length();
while (digitDiff-- != 0) {
hexString.append('0');
}
}
hexString.append(hexSignificand);
hexString.append("p-126"); //$NON-NLS-1$
} else { // normal value
hexString.append("1."); //$NON-NLS-1$
// significand is 23-bits, so there can be 6 hex digits
int fractionDigits = 6;
// remove trailing hex zeros, so Integer.toHexString() won't print
// them
while ((significand != 0) && ((significand & 0xF) == 0)) {
significand > > >= 4;
fractionDigits--;
}
// this assumes Integer.toHexString() returns lowercase characters
String hexSignificand = Integer.toHexString(significand);
// if there are digits left, then insert some '0' chars first
if (significand != 0 && fractionDigits > hexSignificand.length()) {
int digitDiff = fractionDigits - hexSignificand.length();
while (digitDiff-- != 0) {
hexString.append('0');
}
}
hexString.append(hexSignificand);
hexString.append('p');
// remove exponent's 'bias' and convert to a string
hexString.append(Integer.toString(exponent - 127));
}
return hexString.toString();
}
Converts the specified float into its hexadecimal string representation. |
public String toString() {
return Float.toString(value);
}
|
public static String toString(float f) {
return org.apache.harmony.luni.util.NumberConverter.convert(f);
}
Returns a string containing a concise, human-readable description of the
specified float value. |
public static Float valueOf(String string) throws NumberFormatException {
return valueOf(parseFloat(string));
}
Parses the specified string as a float value. |
public static Float valueOf(float f) {
return new Float(f);
}
Returns a {@code Float} instance for the specified float value. |