Build 1.0_r1(from source)

java.lang
Class Float

java.lang.Object
  extended by java.lang.Number
      extended by java.lang.Float
All Implemented Interfaces:
Serializable, Comparable<Float>

public final class Float
extends Number
implements Comparable<Float>

Float is the wrapper for the primitive type float.

Since:
1.0
See Also:
Number, Serialized Form

Field Summary
static float MAX_VALUE
           Constant for the maximum float value, (2 - 2-23) * 2127.
static float MIN_VALUE
           Constant for the minimum float value, 2-149.
static float NaN
           Constant for the Not-a-Number (NaN) value of the float type.
static float NEGATIVE_INFINITY
           Constant for the Negative Infinity value of the float type.
static float POSITIVE_INFINITY
           Constant for the Positive Infinity value of the float type.
static int SIZE
           Constant for the number of bits to represent a float in two's compliment form.
static Class<Float> TYPE
          The java.lang.Class that represents this class.
 
Constructor Summary
Float(double value)
          Constructs a new instance of the receiver which represents the double valued argument.
Float(float value)
          Constructs a new instance of the receiver which represents the float valued argument.
Float(String string)
          Constructs a new instance of this class given a string.
 
Method Summary
 byte byteValue()
          Returns the byte value which the receiver represents
static int compare(float float1, float float2)
          Compares the two floats.
 int compareTo(Float object)
          Compares the receiver with the Float parameter.
 double doubleValue()
          Returns the double value which the receiver represents
 boolean equals(Object object)
          Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
static int floatToIntBits(float value)
          Returns the binary representation of the argument, as an int.
static int floatToRawIntBits(float value)
          Returns the binary representation of the argument, as an int.
 float floatValue()
          Returns the receiver's value as a float.
 int hashCode()
          Returns an integer hash code for the receiver.
static float intBitsToFloat(int bits)
          Returns a float built from the binary representation given in the argument.
 int intValue()
          Returns the int value which the receiver represents
 boolean isInfinite()
          Returns true if the receiver represents an infinite quantity, and false otherwise.
static boolean isInfinite(float f)
          Returns true if the argument represents an infinite quantity, and false otherwise.
 boolean isNaN()
          Returns true if the receiver does not represent a valid float quantity.
static boolean isNaN(float f)
          Returns true if the argument does not represent a valid float quantity.
 long longValue()
          Returns the long value which the receiver represents
static float parseFloat(String string)
          Returns the float which matches the passed in string.
 short shortValue()
          Returns the short value which the receiver represents
static String toHexString(float f)
           Converts a float into a hexadecimal string representation.
 String toString()
          Returns a string containing a concise, human-readable description of the receiver.
static String toString(float f)
          Returns a string containing a printable representation of the argument.
static Float valueOf(float f)
           Returns a Float instance for the float value passed.
static Float valueOf(String string)
          Returns the float which matches the passed in string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final float MAX_VALUE

Constant for the maximum float value, (2 - 2-23) * 2127.

See Also:
Constant Field Values

MIN_VALUE

public static final float MIN_VALUE

Constant for the minimum float value, 2-149.

See Also:
Constant Field Values

NaN

public static final float NaN

Constant for the Not-a-Number (NaN) value of the float type.

See Also:
Constant Field Values

POSITIVE_INFINITY

public static final float POSITIVE_INFINITY

Constant for the Positive Infinity value of the float type.

See Also:
Constant Field Values

NEGATIVE_INFINITY

public static final float NEGATIVE_INFINITY

Constant for the Negative Infinity value of the float type.

See Also:
Constant Field Values

TYPE

public static final Class<Float> TYPE
The java.lang.Class that represents this class.

Since:
1.1

SIZE

public static final int SIZE

Constant for the number of bits to represent a float in two's compliment form.

Since:
1.5
See Also:
Constant Field Values
Constructor Detail

Float

public Float(float value)
Constructs a new instance of the receiver which represents the float valued argument.

Parameters:
value - the float to store in the new instance.

Float

public Float(double value)
Constructs a new instance of the receiver which represents the double valued argument.

Parameters:
value - the double to store in the new instance.

Float

public Float(String string)
      throws NumberFormatException
Constructs a new instance of this class given a string.

Parameters:
string - a string representation of a float quantity.
Throws:
NumberFormatException - if the argument could not be parsed as a float quantity.
Method Detail

compareTo

public int compareTo(Float object)
Compares the receiver with the Float parameter. NaN is equal to NaN, and is greater than other float values. 0f is greater than -0f.

Specified by:
compareTo in interface Comparable<Float>
Parameters:
object - the Float to compare to the receiver
Returns:
Returns greater than zero when this.floatValue() is greater than object.floatValue(), zero when this.floatValue() equals object.floatValue(), and less than zero when this.floatValue() is less than object.floatValue()
Throws:
NullPointerException - if object is null.
Since:
1.2

byteValue

public byte byteValue()
Returns the byte value which the receiver represents

Overrides:
byteValue in class Number
Returns:
byte the value of the receiver.

doubleValue

public double doubleValue()
Returns the double value which the receiver represents

Specified by:
doubleValue in class Number
Returns:
double the value of the receiver.

equals

public boolean equals(Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison. For Floats, the check verifies that the receiver's value's bit pattern matches the bit pattern of the argument, which must also be a Float.

Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the object is the same as this object false if it is different from this object
See Also:
hashCode()

floatToIntBits

public static int floatToIntBits(float value)
Returns the binary representation of the argument, as an int.

Parameters:
value - The float value to convert
Returns:
the bits of the float.

floatToRawIntBits

public static int floatToRawIntBits(float value)
Returns the binary representation of the argument, as an int.

Parameters:
value - The float value to convert
Returns:
the bits of the float.

floatValue

public float floatValue()
Returns the receiver's value as a float.

Specified by:
floatValue in class Number
Returns:
the receiver's value

hashCode

public int hashCode()
Returns an integer hash code for the receiver. Any two objects which answer true when passed to equals must answer the same value for this method.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

intBitsToFloat

public static float intBitsToFloat(int bits)
Returns a float built from the binary representation given in the argument.

Parameters:
bits - the bits of the float
Returns:
the float which matches the bits

intValue

public int intValue()
Returns the int value which the receiver represents

Specified by:
intValue in class Number
Returns:
int the value of the receiver.

isInfinite

public boolean isInfinite()
Returns true if the receiver represents an infinite quantity, and false otherwise.

Returns:
true if the argument is positive or negative infinity false if it is not an infinite value

isInfinite

public static boolean isInfinite(float f)
Returns true if the argument represents an infinite quantity, and false otherwise.

Parameters:
f - value to check for infinitness.
Returns:
true if the argument is positive or negative infinity false if it is not an infinite value

isNaN

public boolean isNaN()
Returns true if the receiver does not represent a valid float quantity.

Returns:
true if the argument is Not A Number false if it is a (potentially infinite) float number

isNaN

public static boolean isNaN(float f)
Returns true if the argument does not represent a valid float quantity.

Parameters:
f - value to check for numberness.
Returns:
true if the argument is Not A Number false if it is a (potentially infinite) float number

longValue

public long longValue()
Returns the long value which the receiver represents

Specified by:
longValue in class Number
Returns:
long the value of the receiver.

parseFloat

public static float parseFloat(String string)
                        throws NumberFormatException
Returns the float which matches the passed in string. NumberFormatException is thrown if the string does not represent a valid float.

Parameters:
string - the value to convert
Returns:
a float which would print as the argument
Throws:
NumberFormatException
Since:
1.2
See Also:
valueOf(String)

shortValue

public short shortValue()
Returns the short value which the receiver represents

Overrides:
shortValue in class Number
Returns:
short the value of the receiver.
Since:
1.1

toString

public String toString()
Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
a printable representation for the receiver.

toString

public static String toString(float f)
Returns a string containing a printable representation of the argument.

Parameters:
f - the float to print
Returns:
a printable representation of the argument.

valueOf

public static Float valueOf(String string)
                     throws NumberFormatException
Returns the float which matches the passed in string. NumberFormatException is thrown if the string does not represent a valid float.

Parameters:
string - the value to convert
Returns:
a float which would print as the argument
Throws:
NumberFormatException

compare

public static int compare(float float1,
                          float float2)
Compares the two floats. NaN is equal to NaN, and is greater than other float values. 0f is greater than -0f.

Parameters:
float1 - the first value to compare
float2 - the second value to compare
Returns:
Returns greater than zero when float1 is greater than float2, zero when float1 equals float2, and less than zero when float1 is less than float2
Since:
1.4

valueOf

public static Float valueOf(float f)

Returns a Float instance for the float value passed. This method is preferred over the constructor, as this method may maintain a cache of instances.

Parameters:
f - The float value.
Returns:
A Float instance.
Since:
1.5

toHexString

public static String toHexString(float f)

Converts a float into a hexadecimal string representation.

Parameters:
f - The float to convert.
Returns:
The hexadecimal string representation of f.
Since:
1.5

Build 1.0_r1(from source)

Please submit a feedback, bug or feature