@Status(stage=PRODUCTION, unitTests=ABSENT) @Review(by="Kees Schotanus", at="2009-09-28") @ThreadSafety(level=IMMUTABLE) public final class CFloat extends Number implements Comparable<CFloat>
Float
is that
this class has (limited) support for arithmetic operations that protect
against both underflow and overflow.Float
is final so this class extends
class Number
instead. This class is immutable and contains private
constructors in combination with static factory methods as suggested by
Joshua Bloch (Effective Java, Second Edition, item 15).Modifier and Type | Field and Description |
---|---|
static float |
HUNDRED_PERCENT
100%.
|
Modifier and Type | Method and Description |
---|---|
CFloat |
add(float value)
Adds the supplied value to this value.
|
static float |
add(float x,
float y)
Adds y to x.
|
byte |
byteValue()
Returns the value of this CFloat as a byte.
|
int |
compareTo(CFloat object)
Compares two CFloat objects numerically.
|
CFloat |
divide(float value)
Divides this value by the supplied value.
|
static float |
divide(float x,
float y)
Divides x by y.
|
double |
doubleValue()
Returns the value of this CFloat as a double.
|
static boolean |
equals(float left,
float right,
float delta)
Determines whether the supplied left and right float are equal to
each other within the limit of the supplied delta.
|
boolean |
equals(Object object)
Determines whether this object and the supplied object are the same.
|
float |
floatValue()
Returns the value of this CFloat as a float.
|
int |
hashCode()
Computes the hash code value for this object.
|
int |
intValue()
Returns the value of this CFloat as an int.
|
long |
longValue()
Returns the value of this CFloat as a long.
|
CFloat |
multiply(float value)
Multiplies this value by the supplied value.
|
static float |
multiply(float x,
float y)
Multiplies x by y.
|
short |
shortValue()
Returns the value of this CFloat as a short.
|
static float |
subtract(float x,
float y)
Subtracts y from x.
|
CFloat |
subtract(long value)
Subtracts the supplied value from this value.
|
String |
toString()
Converts the stored primitive float value to a String.
|
static CFloat |
valueOf(int value)
Returns a CFloat object holding the value of the supplied value.
|
static CFloat |
valueOf(long value)
Returns a CFloat object holding the value of the supplied value.
|
static CFloat |
valueOf(Number value)
Returns a CFloat object holding the value of the supplied value.
|
static CFloat |
valueOf(String value)
Returns a CFloat object holding the parsed value of the supplied value.
|
public static final float HUNDRED_PERCENT
public byte byteValue()
public short shortValue()
shortValue
in class Number
public int intValue()
public long longValue()
public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public static CFloat valueOf(int value)
value
- The int value.IllegalArgumentException
- When the supplied value could not be
converted to a float without losing precision.public static CFloat valueOf(long value)
value
- The long value.IllegalArgumentException
- When the supplied value could not be
converted to a float without losing precision.public static CFloat valueOf(Number value)
value
- The Number that holds the value.NullPointerException
- When the supplied value is null.public static CFloat valueOf(String value)
value
- The String that is parsed.NumberFormatException
- When the supplied value does not contain a
parsable float (this includes a null or empty value).Float.parseFloat(String)
public boolean equals(Object object)
Float.equals(Object)
.public static boolean equals(float left, float right, float delta)
left
- The float on the left of the mathematical equals sign.right
- The float on the right of the mathematical equals sign.delta
- The limit within the two floats are considered to be equal.public int hashCode()
public int compareTo(CFloat object)
compareTo
in interface Comparable<CFloat>
object
- CFloat object to compare with this object.NullPointerException
- When the supplied object is null.Comparable
,
Float.compare(float, float)
public CFloat add(float value)
value
- Value to add to the stored value.ArithmeticException
- When an arithmetic underflow or overflow
occurs, possibly due to one of the values being infinite.add(float, float)
public static float add(float x, float y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic underflow or overflow
occurs, possibly due to one of the values being infinite.public CFloat subtract(long value)
value
- Value to subtract from the stored value.ArithmeticException
- When an arithmetic underflow or overflow
occurs, possibly due to one of the values being infinite.subtract(float, float)
public static float subtract(float x, float y)
x
- Operand one.y
- operand two.ArithmeticException
- When an arithmetic underflow or overflow
occurs, possibly due to one of the values being infinite.public CFloat multiply(float value)
value
- Value to multiply by the stored value.ArithmeticException
- When an arithmetic underflow or overflow
occurs, possibly due to one of the values being infinite.multiply(float, float)
public static float multiply(float x, float y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic underflow or overflow
occurs, possibly due to one of the values being infinite.public CFloat divide(float value)
value
- Value by which this value will be divided.ArithmeticException
- When an arithmetic overflow occurs or when
this value is infinite or when the supplied value is 0.divide(float, float)
public static float divide(float x, float y)
x
- Operand one.y
- Operand two.ArithmeticException
- When an arithmetic overflow occurs or when
the supplied x value is infinite or when the supplied value is 0.Copyright © 2008–2018. All rights reserved.