Final

java.lang
Class Float

java.lang.Object
  |
  +--java.lang.Number
        |
        +--java.lang.Float
All Implemented Interfaces:
Comparable, Serializable

public final class Float
extends Number
implements Comparable

Floats are objects (non-base types) which represent float values.

See Also:
Serialized Form

Field Summary
static float MAX_VALUE
          Largest and smallest possible float values.
static float MIN_VALUE
           
static float NaN
          A value which represents all invalid float results (NaN ==> Not a Number)
static float NEGATIVE_INFINITY
           
static float POSITIVE_INFINITY
          Values to represent infinite results
static Class 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()
          Answers 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.
 int compareTo(Object object)
          Compares the receiver with a Float parameter.
 double doubleValue()
          Answers the double value which the receiver represents
 boolean equals(Object object)
          Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
static int floatToIntBits(float value)
          Answers the binary representation of the argument, as an int.
static int floatToRawIntBits(float value)
          Answers the binary representation of the argument, as an int.
 float floatValue()
          Answers the receiver's value as a float.
 int hashCode()
          Answers an integer hash code for the receiver.
static float intBitsToFloat(int bits)
          Answers a float built from the binary representation given in the argument.
 int intValue()
          Answers the int value which the receiver represents
 boolean isInfinite()
          Answers true if the receiver represents an infinite quantity, and false otherwise.
static boolean isInfinite(float f)
          Answers true if the argument represents an infinite quantity, and false otherwise.
 boolean isNaN()
          Answers true if the receiver does not represent a valid float quantity.
static boolean isNaN(float f)
          Answers true if the argument does not represent a valid float quantity.
 long longValue()
          Answers the long value which the receiver represents
static float parseFloat(String string)
          Answers the float which matches the passed in string.
 short shortValue()
          Answers the short value which the receiver represents
 String toString()
          Answers a string containing a concise, human-readable description of the receiver.
static String toString(float f)
          Answers a string containing a printable representation of the argument.
static Float valueOf(String string)
          Answers 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
Largest and smallest possible float values.

See Also:
Constant Field Values

MIN_VALUE

public static final float MIN_VALUE
See Also:
Constant Field Values

NaN

public static final float NaN
A value which represents all invalid float results (NaN ==> Not a Number)

See Also:
Constant Field Values

POSITIVE_INFINITY

public static final float POSITIVE_INFINITY
Values to represent infinite results

See Also:
Constant Field Values

NEGATIVE_INFINITY

public static final float NEGATIVE_INFINITY
See Also:
Constant Field Values

TYPE

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

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.

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()

compareTo

public int compareTo(Object object)
Compares the receiver with a Float parameter.

Specified by:
compareTo in interface Comparable
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:
ClassCastException - when object is not a Float
See Also:
compareTo(Float)

byteValue

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

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

doubleValue

public double doubleValue()
Answers 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 answers 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)
Answers 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)
Answers 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()
Answers the receiver's value as a float.

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

hashCode

public int hashCode()
Answers 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)
Answers 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()
Answers the int value which the receiver represents

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

isInfinite

public boolean isInfinite()
Answers 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)
Answers 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()
Answers 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)
Answers 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()
Answers 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
Answers 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
NumberFormatException

shortValue

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

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

toString

public String toString()
Answers 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)
Answers 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
Answers 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
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

Final

Licensed Materials - Property of IBM
(C) Copyright IBM Corp. 2006 All Rights Reserved.