|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.dclausen.microfloat.MicroFloat
public final class MicroFloat
A software implementation of IEEE-754 single precision math which does not
rely on the float
data type.
This class overloads the int
data type by storing
float
data in it.
See the
package description
for more information.
MicroDouble
Field Summary | |
---|---|
static int |
E
A single-precision version of MicroDouble.E |
static int |
MAX_VALUE
A constant holding the same value as Float.MAX_VALUE |
static int |
MIN_VALUE
A constant holding the same value as Float.MIN_VALUE |
static int |
NaN
A constant holding the same value as Float.NaN |
static int |
NEGATIVE_INFINITY
A constant holding the same value as Float.NEGATIVE_INFINITY |
static int |
NEGATIVE_ZERO
A constant holding the value of -0.0f |
static int |
ONE
A constant holding the value of 1.0f |
static int |
ONE_HALF
A constant holding the value of 0.5f |
static int |
PI
A single-precision version of MicroDouble.PI |
static int |
POSITIVE_INFINITY
A constant representing the same value as Float.POSITIVE_INFINITY |
static int |
TWO
A constant holding the value of 2.0f |
static int |
ZERO
A constant holding the value of 0.0f |
Constructor Summary | |
---|---|
MicroFloat(int f)
Constructs a newly-allocated MicroFloat object that represents
the argument. |
|
MicroFloat(java.lang.String s)
Constructs a newly-allocated MicroFloat object that represents
the argument. |
Method Summary | |
---|---|
static int |
abs(int f)
Mimics Math.abs(float) |
static int |
add(int f1,
int f2)
Returns the sum of the two float arguments according to
section
15.18.2 of the JLS. |
static byte |
byteValue(int f)
Convert the given float to a byte as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static int |
ceil(int f)
Mimics Math.ceil(double), using single precision. |
static int |
compare(int f1,
int f2)
Mimics Float.compare(float, float). |
static int |
div(int f1,
int f2)
Returns the quotient of the two float arguments according to
section
15.17.2 of the JLS. |
static int |
doubleToFloat(long d)
Convert the given double to a float as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static long |
doubleValue(int f)
Convert the given float to a double as would happen
in a casting operation specified by
section
5.1.2 of the JLS. |
static boolean |
eq(int f1,
int f2)
Returns true if the specified numbers are considered equal
according to
section 15.21.1
of the JLS. |
boolean |
equals(java.lang.Object obj)
Compares this object against the specified object. |
int |
floatValue()
Returns the float value of this MicroFloat
object. |
static int |
floor(int f)
Mimics Math.floor(double), using single precision. |
static boolean |
ge(int f1,
int f2)
Returns true if the first argument is considered greater than
or equal to the second argument according to
section
15.20.1 of the JLS. |
static boolean |
gt(int f1,
int f2)
Returns true if the first argument is considered greater than
the second argument according to
section
15.20.1 of the JLS. |
int |
hashCode()
Returns a hash code for this MicroFloat object. |
static int |
intToFloat(int x)
Convert the given int to a float as would happen
in a casting operation specified by
section
5.1.2 of the JLS. |
static int |
intValue(int f)
Convert the given float to an int as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static boolean |
isInfinite(int f)
Mimics Float.isInfinite(float) |
static boolean |
isNaN(int f)
Mimics Float.isNaN(float) |
static boolean |
isZero(int f)
Returns true if the specified number has zero
magnitude, false otherwise. |
static boolean |
le(int f1,
int f2)
Returns true if the first argument is considered less than
or equal to the second argument according to
section
15.20.1 of the JLS. |
static int |
longToFloat(long x)
Convert the given long to a float as would happen
in a casting operation specified by
section
5.1.2 of the JLS. |
static long |
longValue(int f)
Convert the given float to a long as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static boolean |
lt(int f1,
int f2)
Returns true if the first argument is considered less than
the second argument according to
section
15.20.1 of the JLS. |
static int |
max(int f1,
int f2)
Mimics Math.max(float, float). |
static int |
min(int f1,
int f2)
Mimics Math.min(float, float). |
static int |
mod(int f1,
int f2)
Returns the remainder of the two float arguments according to
section
15.17.3 of the JLS. |
static int |
mul(int f1,
int f2)
Returns the product of the two float arguments according to
section
15.17.1 of the JLS. |
static boolean |
ne(int f1,
int f2)
Returns true if the specified numbers are considered unequal
according to
section
15.21.1 of the JLS. |
static int |
negate(int f)
Returns the negation of a float value. |
static int |
parseFloat(java.lang.String s)
Mimics Float.parseFloat(String). |
static int |
rint(int f)
Mimics Math.rint(double), using single precision. |
static int |
round(int f)
Mimics Math.round(double), using single precision. |
static short |
shortValue(int f)
Convert the given float to a short as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static int |
sub(int f1,
int f2)
Returns the difference of the two float arguments according to
section
15.18.2 of the JLS. |
java.lang.String |
toString()
Returns a String object representing this MicroFloat's value. |
static java.lang.String |
toString(int f)
Mimics Float.toString(float). |
static int |
truncate(int f)
Returns the float of greatest magnitude (furthest from zero)
that is equal to a mathematical integer and which has a mignitude not
greater than the argument's magnitude. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int POSITIVE_INFINITY
public static final int NEGATIVE_INFINITY
public static final int NaN
public static final int MAX_VALUE
public static final int MIN_VALUE
public static final int E
MicroDouble.E
public static final int PI
MicroDouble.PI
public static final int ZERO
public static final int NEGATIVE_ZERO
public static final int ONE
public static final int TWO
public static final int ONE_HALF
Constructor Detail |
---|
public MicroFloat(int f)
MicroFloat
object that represents
the argument.
f
- the float
value to be represented by the MicroFloat
.public MicroFloat(java.lang.String s)
MicroFloat
object that represents
the argument.
s
- a String
to be converted to a MicroFloat
.
java.lang.NumberFormatException
- if the String
does not contain a
parsable number.parseFloat(String)
Method Detail |
---|
public static boolean isNaN(int f)
public static boolean isInfinite(int f)
public static boolean isZero(int f)
true
if the specified number has zero
magnitude, false
otherwise.
f
- the float
value to be tested.
true
if the value of the argument is positive
zero or negative zero; false
otherwise.public static int abs(int f)
public static int negate(int f)
float
value.
Special cases:
This method takes the place of the unary -
operator.
f
- the float
value whose negated value is to be
determined
public static boolean eq(int f1, int f2)
true
if the specified numbers are considered equal
according to
section 15.21.1
of the JLS. Special cases:
This method takes the place of the ==
operator.
f1
- the first float
value to be compared.f2
- the second float
value to be compared.
true
if the two values are considered equal;
false
otherwise.public static boolean ne(int f1, int f2)
true
if the specified numbers are considered unequal
according to
section
15.21.1 of the JLS. Special cases:
ne
is always the opposite of the value
returned by eq
for the same arguments.
This method takes the place of the !=
operator.
f1
- the first float
value to be compared.f2
- the second float
value to be compared.
true
if the two values are considered equal;
false
otherwise.public static boolean lt(int f1, int f2)
true
if the first argument is considered less than
the second argument according to
section
15.20.1 of the JLS. Special cases:
This method takes the place of the <
operator.
f1
- the first float
value to be compared.f2
- the second float
value to be compared.
true
if the first value is less than the second value;
false
otherwise.public static boolean le(int f1, int f2)
true
if the first argument is considered less than
or equal to the second argument according to
section
15.20.1 of the JLS. Special cases:
This method takes the place of the <=
operator.
f1
- the first float
value to be compared.f2
- the second float
value to be compared.
true
if the first value is less than or equal to
the second value; false
otherwise.public static boolean gt(int f1, int f2)
true
if the first argument is considered greater than
the second argument according to
section
15.20.1 of the JLS. Special cases:
This method takes the place of the >
operator.
f1
- the first float
value to be compared.f2
- the second float
value to be compared.
true
if the first value is greater than the second value;
false
otherwise.public static boolean ge(int f1, int f2)
true
if the first argument is considered greater than
or equal to the second argument according to
section
15.20.1 of the JLS. Special cases:
This method takes the place of the >=
operator.
f1
- the first float
value to be compared.f2
- the second float
value to be compared.
true
if the first value is greater than or equal to
the second value; false
otherwise.public static int compare(int f1, int f2)
Note that when using this method (as well as Float.compare
),
the following rules apply:
NaN
is considered
to be equal to itself and greater than all other
float
values (including
POSITIVE_INFINITY
).
0.0
is considered to be greater
than -0.0
.
public static int max(int f1, int f2)
public static int min(int f1, int f2)
public static int intToFloat(int x)
int
to a float
as would happen
in a casting operation specified by
section
5.1.2 of the JLS. This is a widening primitive conversion which
will not result in a loss of magnitude, but might result in a loss of
precision.
x
- the int
to be converted
float
representation of the argumentpublic static int longToFloat(long x)
long
to a float
as would happen
in a casting operation specified by
section
5.1.2 of the JLS. This is a widening primitive conversion which
will not result in a loss of magnitude, but might result in a loss of
precision.
x
- the long
to be converted
float
representation of the argumentpublic static int doubleToFloat(long d)
double
to a float
as would happen
in a casting operation specified by
section
5.1.3 of the JLS. This is a narrowing primitive conversion which
may result in a loss of magnitude and/or precision.
d
- the double
to be converted
float
representation of the argumentpublic static byte byteValue(int f)
float
to a byte
as would happen
in a casting operation specified by
section
5.1.3 of the JLS. This is a narrowing primitive conversion which
may result in a loss of magnitude and/or precision.
Note that this is a non-intuitive conversion. If the argument is outside of the range of the byte type, the result is basically meaningless.
f
- the float
to be converted
byte
representation of the argumentpublic static short shortValue(int f)
float
to a short
as would happen
in a casting operation specified by
section
5.1.3 of the JLS. This is a narrowing primitive conversion which
may result in a loss of magnitude and/or precision.
Note that this is a non-intuitive conversion. If the argument is outside of the range of the short type, the result is basically meaningless.
f
- the float
to be converted
short
representation of the argumentpublic static int intValue(int f)
float
to an int
as would happen
in a casting operation specified by
section
5.1.3 of the JLS. This is a narrowing primitive conversion which
may result in a loss of magnitude and/or precision.
f
- the float
to be converted
int
representation of the argumentpublic static long longValue(int f)
float
to a long
as would happen
in a casting operation specified by
section
5.1.3 of the JLS. This is a narrowing primitive conversion which
may result in a loss of magnitude and/or precision.
f
- the float
to be converted
long
representation of the argumentpublic static long doubleValue(int f)
float
to a double
as would happen
in a casting operation specified by
section
5.1.2 of the JLS. This is a widening primitive conversion which
will result in neither a loss of magnitude nor precision.
f
- the float
to be converted
double
representation of the argumentpublic static int add(int f1, int f2)
float
arguments according to
section
15.18.2 of the JLS.
This method takes the place of the binary +
operator.
f1
- the first float
value to be summed.f2
- the second float
value to be summed.
public static int sub(int f1, int f2)
float
arguments according to
section
15.18.2 of the JLS.
This method takes the place of the binary -
operator.
f1
- the first float
valuef2
- the second float
value
public static int mul(int f1, int f2)
float
arguments according to
section
15.17.1 of the JLS.
This method takes the place of the *
operator.
f1
- the first float
valuef2
- the second float
value
public static int div(int f1, int f2)
float
arguments according to
section
15.17.2 of the JLS.
This method takes the place of the /
operator.
f1
- the float
dividendf2
- the float
divisor
public static int mod(int f1, int f2)
float
arguments according to
section
15.17.3 of the JLS.
This method takes the place of the %
operator.
f1
- the float
dividendf2
- the float
divisor
public static int truncate(int f)
float
of greatest magnitude (furthest from zero)
that is equal to a mathematical integer and which has a mignitude not
greater than the argument's magnitude. Special cases:
f
- a float
value.
float
of greatest magnitude (furthest from zero)
whose magnitude is not greater than the argument's and which
is equal to a mathematical integer.public static int rint(int f)
public static int floor(int f)
public static int ceil(int f)
public static int round(int f)
public static int parseFloat(java.lang.String s)
This implementation is known to be inaccurate, and
does not always return the same value as
Float.parseFloat
. However the difference should be no
greater than 1 ulp.
java.lang.NumberFormatException
- if the string does not contain a
parsable number.public static java.lang.String toString(int f)
This implementation is known to be inaccurate, and
does not always return the same value as
Float.toString
. However the difference should be no
greater than 1 ulp.
public int floatValue()
float
value of this MicroFloat
object.
public java.lang.String toString()
toString(floatValue())
.
toString
in class java.lang.Object
toString(int)
public int hashCode()
MicroFloat
object.
Equivalent to floatValue().
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
((obj instanceof MicroFloat) && (compare(((MicroFloat) obj).floatValue(), floatValue()) == 0))
equals
in class java.lang.Object
compare(int, int)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |