java.lang
Class Float

java.lang.Object
  extended by java.lang.Number
      extended by java.lang.Float

public final class Float
extends Number

Minimal Float implementation.

Author:
Lawrie Griffiths, Sven Köhler

Field Summary
static float NaN
           
static float NEGATIVE_INFINITY
           
static float POSITIVE_INFINITY
           
static int SIZE
           
 
Constructor Summary
Float(double value)
           
Float(float value)
          Constructs a newly allocated Float object that represents the primitive float argument.
Float(String s)
           
 
Method Summary
 byte byteValue()
          Return the byte value of this Number.
 double doubleValue()
          Return the double value of this Number.
 boolean equals(Object o)
           
static int floatToIntBits(float value)
          Returns the bit representation of a single-float value.
static int floatToRawIntBits(float value)
          Returns the bit representation of a single-float value.
 float floatValue()
          Returns the float value of this Float object.
 int hashCode()
           
static float intBitsToFloat(int value)
          Returns the single-float corresponding to a given bit represention.
 int intValue()
          Return the int value of this Number.
 boolean isInfinite()
           
static boolean isInfinite(float v)
           
 boolean isNaN()
           
static boolean isNaN(float val)
           
 long longValue()
          Return the long value of this Number.
static float parseFloat(String s)
          Converts a String value into a float
 short shortValue()
          Return the short value of this Number.
 String toString()
           
static String toString(float f)
          Convert a float to a String
static Float valueOf(float f)
           
static Float valueOf(String s)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

POSITIVE_INFINITY

public static final float POSITIVE_INFINITY
See Also:
Constant Field Values

NEGATIVE_INFINITY

public static final float NEGATIVE_INFINITY
See Also:
Constant Field Values

NaN

public static final float NaN
See Also:
Constant Field Values

SIZE

public static final int SIZE
See Also:
Constant Field Values
Constructor Detail

Float

public Float(double value)

Float

public Float(float value)
Constructs a newly allocated Float object that represents the primitive float argument.

Parameters:
value - - the value to be represented by the Float.

Float

public Float(String s)
Method Detail

byteValue

public byte byteValue()
Description copied from class: Number
Return the byte value of this Number.

Overrides:
byteValue in class Number
Returns:
the byte value

doubleValue

public double doubleValue()
Description copied from class: Number
Return the double value of this Number.

Specified by:
doubleValue in class Number
Returns:
the double value

equals

public boolean equals(Object o)
Overrides:
equals in class Object

floatToRawIntBits

public static int floatToRawIntBits(float value)
Returns the bit representation of a single-float value. The result is a representation of the floating-point argument according to the IEEE 754 floating-point "single precision" bit layout. In all cases, the result is an integer that, when given to the intBitsToFloat(int) method, will produce a floating-point value equal to the argument to floatToRawIntBits.

Parameters:
value - a floating-point number.
Returns:
the bits that represent the floating-point number.

floatToIntBits

public static int floatToIntBits(float value)
Returns the bit representation of a single-float value. The result is a representation of the floating-point argument according to the IEEE 754 floating-point "single precision" bit layout. Unlike floatToRawIntBits this method does collapse all NaN values into a standard single value. This value is 0x7fc00000.

Parameters:
value - a floating-point number.
Returns:
the bits that represent the floating-point number.

floatValue

public float floatValue()
Returns the float value of this Float object.

Specified by:
floatValue in class Number
Returns:
the float value represented by this object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

intBitsToFloat

public static float intBitsToFloat(int value)
Returns the single-float corresponding to a given bit represention. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "single precision" bit layout.

If the argument is 0x7f800000, the result is positive infinity.

If the argument is 0xff800000, the result is negative infinity.

If the argument is any value in the range 0x7f800001 through 0x7fffffff or in the range 0xff800001 through 0xffffffff, the result is NaN. All IEEE 754 NaN values of type float are, in effect, lumped together by the Java programming language into a single float value called NaN. Distinct values of NaN are only accessible by use of the Float.floatToRawIntBits method.

In all other cases, let s, e, and m be three values that can be computed from the argument:

 int s = ((bits >> 31) == 0) ? 1 : -1;
 int e = ((bits >> 23) & 0xff);
 int m = (e == 0) ?
                                 (bits & 0x7fffff) << 1 :
                                 (bits & 0x7fffff) | 0x800000;
 
Then the floating-point result equals the value of the mathematical expression s·m·2e-150.

Parameters:
value - an integer.
Returns:
the single-format floating-point value with the same bit pattern.

intValue

public int intValue()
Description copied from class: Number
Return the int value of this Number.

Specified by:
intValue in class Number
Returns:
the int value

isInfinite

public boolean isInfinite()

isInfinite

public static boolean isInfinite(float v)

isNaN

public boolean isNaN()

isNaN

public static boolean isNaN(float val)

longValue

public long longValue()
Description copied from class: Number
Return the long value of this Number.

Specified by:
longValue in class Number
Returns:
the long value

parseFloat

public static float parseFloat(String s)
                        throws NumberFormatException
Converts a String value into a float

Parameters:
s - String representation of float. Must only contain numbers and an optional decimal, and optional - sign at front.
Returns:
float number
Throws:
NumberFormatException

shortValue

public short shortValue()
Description copied from class: Number
Return the short value of this Number.

Overrides:
shortValue in class Number
Returns:
the short value

toString

public String toString()
Overrides:
toString in class Object

toString

public static String toString(float f)
Convert a float to a String

Parameters:
f - the float to be converted
Returns:
the String representation of the float

valueOf

public static Float valueOf(float f)

valueOf

public static Float valueOf(String s)