|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectnet.dclausen.microfloat.MicroDouble
public class MicroDouble
A software implementation of IEEE-754 double precision math which does not
rely on the double data type.
This class overloads the long data type by storing
double data in it.
See the
package description
for more information.
Float| Field Summary | |
|---|---|
static long |
E
A constant holding the same value as Math.E |
static long |
EIGHT
A constant holding the value of 8.0d |
static long |
FIVE
A constant holding the value of 5.0d |
static long |
FOUR
A constant holding the value of 4.0d |
static long |
LN2
A constant holding the natural logarithm of 2 |
static long |
MAX_VALUE
A constant holding the same value as Double.MAX_VALUE |
static long |
MIN_VALUE
A constant holding the same value as Double.MIN_VALUE |
static long |
NaN
A constant holding the same value as Double.NaN |
static long |
NEGATIVE_INFINITY
A constant holding the same value as Double.NEGATIVE_INFINITY |
static long |
NEGATIVE_ONE
A constant holding the value of -1.0d |
static long |
NEGATIVE_ZERO
A constant holding the value of -0.0d |
static long |
ONE
A constant holding the value of 1.0d |
static long |
ONE_EIGHTH
A constant holding the value of 0.125d |
static long |
ONE_FOURTH
A constant holding the value of 0.25d |
static long |
ONE_HALF
A constant holding the value of 0.5d |
static long |
ONE_HUNDRED
A constant holding the value of 100.0d |
static long |
ONE_THIRD
A constant holding the value of (1.0d / 3.0d) |
static long |
PI
A constant holding the same value as Math.PI |
static long |
POSITIVE_INFINITY
A constant holding the same value as Double.POSITIVE_INFINITY |
static long |
SIX
A constant holding the value of 6.0d |
static long |
TEN
A constant holding the value of 10.0d |
static long |
THREE
A constant holding the value of 3.0d |
static long |
THREE_HALVES
A constant holding the value of 1.5d |
static long |
TWO
A constant holding the value of 2.0d |
static long |
ZERO
A constant holding the value of 0.0d |
| Constructor Summary | |
|---|---|
MicroDouble(long d)
Constructs a newly-allocated MicroDouble object that represents
the argument. |
|
MicroDouble(java.lang.String s)
Constructs a newly-allocated MicroDouble object that represents
the argument. |
|
| Method Summary | |
|---|---|
static long |
abs(long d)
Mimics Math.abs(double) |
static long |
acos(long d)
Mimics Math.acos(double). |
static long |
acosh(long d)
Returns the arc hyperbolic cosine of an angle. |
static long |
add(long d1,
long d2)
Returns the sum of the two double arguments according to
section
15.18.2 of the JLS. |
static long |
asin(long d)
Mimics Math.asin(double). |
static long |
asinh(long d)
Returns the arc hyperbolic sine of an angle. |
static long |
atan(long d)
Mimics Math.atan(double). |
static long |
atanh(long d)
Returns the arc hyperbolic tangent of an angle. |
static byte |
byteValue(long d)
Convert the given double to a byte as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static long |
ceil(long d)
Mimcs Math.ceil(double). |
static long |
combinations(long d1,
long d2)
Return the number of ways of obtaining an unordered subset of d2 elements from a set of d1 elements. |
static int |
compare(long d1,
long d2)
Mimics Double.compare(double, double). |
static long |
cos(long d)
Mimics Math.cos(double). |
static long |
cosh(long d)
Returns the hyperbolic cosine of an angle. |
static long |
div(long d1,
long d2)
Returns the quotient of the two double arguments according to
section
15.17.2 of the JLS. |
long |
doubleValue()
Returns the double value of this MicroDouble
object. |
static boolean |
eq(long d1,
long d2)
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. |
static long |
exp(long d)
Mimics Math.exp(double). |
static long |
expm1(long d)
Returns Euler's number e raised to the power of a double value, less 1, computed in a way that is accurate
even when the value of d is close to zero. |
static long |
factorial(long d)
Returns the factorial of d. |
static long |
floatToDouble(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 int |
floatValue(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 |
floor(long d)
Mimics Math.floor(double). |
static long |
gamma(long d)
Returns the complete gamma function of d. |
static boolean |
ge(long d1,
long d2)
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 long |
gradiansToRadians(long anggrad)
|
static boolean |
gt(long d1,
long d2)
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 MicroDouble object. |
static long |
IEEEremainder(long d1,
long d2)
Mimics Math.IEEEremainder(double, double). |
static long |
intToDouble(int x)
Convert the given int to a double as would happen
in a casting operation specified by
section
5.1.2 of the JLS. |
static int |
intValue(long d)
Convert the given double to an int as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static boolean |
isInfinite(long d)
Mimics Double.isInfinite(double) |
static boolean |
isNaN(long d)
Mimics Double.isNaN(double) |
static boolean |
isZero(long d)
Returns true if the specified number has zero
magnitude, false otherwise. |
static boolean |
le(long d1,
long d2)
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 long |
lgamma(long d)
Returns the natural logarithm of the absolute value of the gamma function of d. |
static long |
log(long d)
Mimics Math.log(double). |
static long |
log(long d,
long base)
Returns the logarithm of a double value using a specified
base. |
static long |
log10(long d)
Returns the base 10 logarithm of a double
value. |
static long |
log1p(long d)
Returns the natural logarithm of 1 + d, computed in a way
that is accurate even when the value of d is close to zero. |
static long |
longToDouble(long x)
Convert the given long to a double as would happen
in a casting operation specified by
section
5.1.2 of the JLS. |
static long |
longValue(long d)
Convert the given double to a long as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static boolean |
lt(long d1,
long d2)
Returns true if the first argument is considered less than
the second argument according to
section
15.20.1 of the JLS. |
static long |
max(long d1,
long d2)
Mimics Math.max(double, double) |
static long |
min(long d1,
long d2)
Mimics Math.min(double, double) |
static long |
mod(long d1,
long d2)
Returns the remainder of the two double arguments according to
section
15.17.3 of the JLS. |
static long |
mul(long d1,
long d2)
Returns the product of the two double arguments according to
section
15.17.1 of the JLS. |
static boolean |
ne(long d1,
long d2)
Returns true if the specified numbers are considered unequal
according to
section
15.21.1 of the JLS. |
static long |
negate(long d)
Returns the negation of a double value. |
static long |
parseDouble(java.lang.String s)
Mimics Double.parseDouble(String). |
static long |
percentChange(long d1,
long d2)
Returns the difference of d2 and d1, expressed as a percentage of d1. |
static long |
percentTotal(long d1,
long d2)
Returns d2 expressed as a percentage of d1 |
static long |
permutations(long d1,
long d2)
Return the number of ways of obtaining an ordered subset of d2 elements from a set of d1 elements. |
static long |
pow(long d1,
long d2)
Mimics Math.pow(double, double). |
static long |
random()
Mimics Math.random() |
static long |
rint(long d)
Mimics Math.rint(double). |
static long |
round(long d)
Mimcs Math.round(double). |
static long |
scalbn(long d,
int n)
Returns the value of the first argument, multiplied by 2 raised to the power of the second argument. |
static short |
shortValue(long d)
Convert the given double to a short as would happen
in a casting operation specified by
section
5.1.3 of the JLS. |
static long |
sin(long d)
Mimics Math.sin(double). |
static long |
sinh(long d)
Returns the hyperbolic sine of an angle. |
static long |
sqrt(long d)
Mimics Math.sqrt(double). |
static long |
sub(long d1,
long d2)
Returns the difference of the two double arguments according to
section
15.18.2 of the JLS. |
static long |
tan(long d)
Mimics Math.tan(double). |
static long |
tanh(long d)
Returns the hyperbolic tangent of an angle. |
static long |
toDegrees(long angrad)
Mimics Math.toDegrees(double). |
static long |
toGradians(long angrad)
|
static long |
toRadians(long angdeg)
Mimics Math.toRadians(double). |
java.lang.String |
toString()
Returns a String object representing this MicroDouble's value. |
static java.lang.String |
toString(long d)
Mimics Double.toString(double). |
static java.lang.String |
toString(long d,
int maxStringLength)
Returns a string representation of the double argument, rounded so that the returned String is no longer than
maxStringLength characters (or 9 characters, if
maxStringLength is less than 9). |
static long |
truncate(long d)
Returns the double 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 long POSITIVE_INFINITY
public static final long NEGATIVE_INFINITY
public static final long NaN
public static final long MAX_VALUE
public static final long MIN_VALUE
public static final long E
public static final long PI
public static final long ZERO
public static final long NEGATIVE_ZERO
public static final long ONE
public static final long NEGATIVE_ONE
public static final long TWO
public static final long THREE
public static final long FOUR
public static final long FIVE
public static final long SIX
public static final long EIGHT
public static final long TEN
public static final long ONE_HUNDRED
public static final long THREE_HALVES
public static final long ONE_HALF
public static final long ONE_THIRD
public static final long ONE_FOURTH
public static final long ONE_EIGHTH
public static final long LN2
| Constructor Detail |
|---|
public MicroDouble(long d)
MicroDouble object that represents
the argument.
d - the double value to be represented by the MicroDouble.public MicroDouble(java.lang.String s)
MicroDouble object that represents
the argument.
s - a String to be converted to a MicroDouble.
java.lang.NumberFormatException - if the String does not contain a
parsable number.parseDouble(String)| Method Detail |
|---|
public static boolean isNaN(long d)
public static boolean isInfinite(long d)
public static boolean isZero(long d)
true if the specified number has zero
magnitude, false otherwise.
d - the double value to be tested.
true if the value of the argument is positive
zero or negative zero; false otherwise.public static long abs(long d)
public static long negate(long d)
double value.
Special cases:
This method takes the place of the unary - operator.
d - the double value whose negated value is to be
determined
public static boolean eq(long d1,
long d2)
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.
d1 - the first double value to be compared.d2 - the second double value to be compared.
true if the two values are considered equal;
false otherwise.
public static boolean ne(long d1,
long d2)
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.
d1 - the first double value to be compared.d2 - the second double value to be compared.
true if the two values are considered equal;
false otherwise.
public static boolean lt(long d1,
long d2)
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.
d1 - the first double value to be compared.d2 - the second double value to be compared.
true if the first value is less than the second value;
false otherwise.
public static boolean le(long d1,
long d2)
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.
d1 - the first double value to be compared.d2 - the second double value to be compared.
true if the first value is less than or equal to
the second value; false otherwise.
public static boolean gt(long d1,
long d2)
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.
d1 - the first double value to be compared.d2 - the second double value to be compared.
true if the first value is greater than the second value;
false otherwise.
public static boolean ge(long d1,
long d2)
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.
d1 - the first double value to be compared.d2 - the second double value to be compared.
true if the first value is greater than or equal to
the second value; false otherwise.
public static int compare(long d1,
long d2)
Note that when using this method (as well as Double.compare),
the following rules apply:
NaN is considered
to be equal to itself and greater than all other
double values (including
POSITIVE_INFINITY).
0.0 is considered to be greater
than -0.0.
public static long max(long d1,
long d2)
public static long min(long d1,
long d2)
public static long intToDouble(int x)
int 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.
x - the int to be converted
double representation of the argumentpublic static long longToDouble(long x)
long 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 not result in a loss of magnitude, but might result in a loss of
precision.
x - the long to be converted
double representation of the argumentpublic static long floatToDouble(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 byte byteValue(long d)
double 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.
d - the double to be converted
byte representation of the argumentpublic static short shortValue(long d)
double 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.
d - the double to be converted
short representation of the argumentpublic static int intValue(long d)
double 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.
d - the double to be converted
int representation of the argumentpublic static long longValue(long d)
double 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.
d - the double to be converted
long representation of the argumentpublic static int floatValue(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 long random()
public static long add(long d1,
long d2)
double arguments according to
section
15.18.2 of the JLS.
This method takes the place of the + operator.
d1 - the first double value to be summed.d2 - the second double value to be summed.
public static long sub(long d1,
long d2)
double arguments according to
section
15.18.2 of the JLS.
This method takes the place of the binary - operator.
d1 - the first double valued2 - the second double value
public static long mul(long d1,
long d2)
double arguments according to
section
15.17.1 of the JLS.
This method takes the place of the * operator.
d1 - the first double valued2 - the second double value
public static long div(long d1,
long d2)
double arguments according to
section
15.17.2 of the JLS.
This method takes the place of the / operator.
d1 - the double dividendd2 - the double divisor
public static long mod(long d1,
long d2)
double arguments according to
section
15.17.3 of the JLS.
This method takes the place of the % operator.
d1 - the double dividendd2 - the double divisor
IEEEremainder(long, long)public static long truncate(long d)
double 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:
d - a double value.
double 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 long rint(long d)
public static long floor(long d)
public static long ceil(long d)
public static long round(long d)
public static long parseDouble(java.lang.String s)
See the notes on toString for some caveats on String
conversion.
java.lang.NumberFormatException - if the string does not contain a
parsable number.toString(long)public static java.lang.String toString(long d)
String conversion is a bit of a gray area. The J2SE implementation of
this function (Double.toString(double) has some problems.
Often times it does not return the shortest valid String, even though it
claims to do so, and it has a few
corner cases where it behaves oddly (e.g. 0.001 gets converted to
the String "0.0010").
The implementation in MicroDouble uses a much simpler table-based
algorithm. It frequently returns slightly different results than
Double.toString(double). Sometimes the results are better,
and sometimes worse. Ususally the difference is confined to the last
character, which may be different or missing in one of the results.
public static java.lang.String toString(long d,
int maxStringLength)
String is no longer than
maxStringLength characters (or 9 characters, if
maxStringLength is less than 9).
d - the double to be converted.maxStringLength - the maximum length of the returned string
toString(long)public static long toDegrees(long angrad)
public static long toRadians(long angdeg)
public static long toGradians(long angrad)
public static long gradiansToRadians(long anggrad)
public static long scalbn(long d,
int n)
int, not a float or double.
d - a double value.n - an int value.
d * 2n.
public static long IEEEremainder(long d1,
long d2)
public static long sqrt(long d)
public static long exp(long d)
public static long expm1(long d)
double value, less 1, computed in a way that is accurate
even when the value of d is close to zero.
d - the exponent to raise e to.
d - 1,
where e is the base of the natural logarithms.exp(long),
log1p(long)
public static long pow(long d1,
long d2)
public static long log(long d,
long base)
double value using a specified
base. For most arguments, the return value is computed as:
log(d) / log(base). If base is E or
10 the dedicated log function is used. If base
is zero, infinite, NaN, or negative, NaN is
returned.
d - a double value greater than 0.0.base - a double value greater than 0.0.
base dpublic static long log10(long d)
double
value.
d - a double value greater than 0.0.
dpublic static long log(long d)
public static long log1p(long d)
1 + d, computed in a way
that is accurate even when the value of d is close to zero.
d - a double value greater than -1.0.
d, the natural logarithm of
d + 1.log(long),
expm1(long)public static long sin(long d)
public static long cos(long d)
public static long tan(long d)
public static final long asin(long d)
public static long acos(long d)
public static long atan(long d)
public static long cosh(long d)
d - an angle, in radians.
public static long sinh(long d)
d - an angle, in radians.
public static long tanh(long d)
d - an angle, in radians.
public static long acosh(long d)
d - the value whose arc hyperbolic cosine is to be returned.
public static long asinh(long d)
d - the value whose arc hyperbolic sine is to be returned.
public static long atanh(long d)
d - the value whose arc hyperbolic tangent is to be returned.
public static long percentChange(long d1,
long d2)
d1 - the "starting" valued2 - the "final" value
public static long percentTotal(long d1,
long d2)
d1 - the "base" valued2 - the other value
public static long factorial(long d)
This is a naive implentation. TODO: make this better.
d - a double value.
public static long permutations(long d1,
long d2)
d1 - a double valued2 - a double value
factorial(long),
combinations(long, long)
public static long combinations(long d1,
long d2)
d1 - a double valued2 - a double value
factorial(long),
permutations(long, long)public static long gamma(long d)
d - a double value
lgamma(long)public static long lgamma(long d)
d - a double value
gamma(long)public long doubleValue()
double value of this MicroDouble
object.
public java.lang.String toString()
toString(doubleValue()).
toString in class java.lang.ObjecttoString(long)public int hashCode()
MicroDouble object.
Equivalent to (int) (doubleValue() ^ (doubleValue >>> 32))
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
((obj instanceof MicroDouble) && (compare(((MicroDouble) obj).doubleValue(), doubleValue()) == 0))
equals in class java.lang.Objectcompare(long, long)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||