net.dclausen.microfloat
Class MicroDouble

java.lang.Object
  extended by net.dclausen.microfloat.MicroDouble

public class MicroDouble
extends java.lang.Object

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.

See Also:
Double, Math, 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

POSITIVE_INFINITY

public static final long POSITIVE_INFINITY
A constant holding the same value as Double.POSITIVE_INFINITY

See Also:
Constant Field Values

NEGATIVE_INFINITY

public static final long NEGATIVE_INFINITY
A constant holding the same value as Double.NEGATIVE_INFINITY

See Also:
Constant Field Values

NaN

public static final long NaN
A constant holding the same value as Double.NaN

See Also:
Constant Field Values

MAX_VALUE

public static final long MAX_VALUE
A constant holding the same value as Double.MAX_VALUE

See Also:
Constant Field Values

MIN_VALUE

public static final long MIN_VALUE
A constant holding the same value as Double.MIN_VALUE

See Also:
Constant Field Values

E

public static final long E
A constant holding the same value as Math.E

See Also:
Constant Field Values

PI

public static final long PI
A constant holding the same value as Math.PI

See Also:
Constant Field Values

ZERO

public static final long ZERO
A constant holding the value of 0.0d

See Also:
Constant Field Values

NEGATIVE_ZERO

public static final long NEGATIVE_ZERO
A constant holding the value of -0.0d

See Also:
Constant Field Values

ONE

public static final long ONE
A constant holding the value of 1.0d

See Also:
Constant Field Values

NEGATIVE_ONE

public static final long NEGATIVE_ONE
A constant holding the value of -1.0d

See Also:
Constant Field Values

TWO

public static final long TWO
A constant holding the value of 2.0d

See Also:
Constant Field Values

THREE

public static final long THREE
A constant holding the value of 3.0d

See Also:
Constant Field Values

FOUR

public static final long FOUR
A constant holding the value of 4.0d

See Also:
Constant Field Values

FIVE

public static final long FIVE
A constant holding the value of 5.0d

See Also:
Constant Field Values

SIX

public static final long SIX
A constant holding the value of 6.0d

See Also:
Constant Field Values

EIGHT

public static final long EIGHT
A constant holding the value of 8.0d

See Also:
Constant Field Values

TEN

public static final long TEN
A constant holding the value of 10.0d

See Also:
Constant Field Values

ONE_HUNDRED

public static final long ONE_HUNDRED
A constant holding the value of 100.0d

See Also:
Constant Field Values

THREE_HALVES

public static final long THREE_HALVES
A constant holding the value of 1.5d

See Also:
Constant Field Values

ONE_HALF

public static final long ONE_HALF
A constant holding the value of 0.5d

See Also:
Constant Field Values

ONE_THIRD

public static final long ONE_THIRD
A constant holding the value of (1.0d / 3.0d)

See Also:
Constant Field Values

ONE_FOURTH

public static final long ONE_FOURTH
A constant holding the value of 0.25d

See Also:
Constant Field Values

ONE_EIGHTH

public static final long ONE_EIGHTH
A constant holding the value of 0.125d

See Also:
Constant Field Values

LN2

public static final long LN2
A constant holding the natural logarithm of 2

See Also:
Constant Field Values
Constructor Detail

MicroDouble

public MicroDouble(long d)
Constructs a newly-allocated MicroDouble object that represents the argument.

Parameters:
d - the double value to be represented by the MicroDouble.

MicroDouble

public MicroDouble(java.lang.String s)
Constructs a newly-allocated MicroDouble object that represents the argument.

Parameters:
s - a String to be converted to a MicroDouble.
Throws:
java.lang.NumberFormatException - if the String does not contain a parsable number.
See Also:
parseDouble(String)
Method Detail

isNaN

public static boolean isNaN(long d)
Mimics Double.isNaN(double)


isInfinite

public static boolean isInfinite(long d)
Mimics Double.isInfinite(double)


isZero

public static boolean isZero(long d)
Returns true if the specified number has zero magnitude, false otherwise.

Parameters:
d - the double value to be tested.
Returns:
true if the value of the argument is positive zero or negative zero; false otherwise.

abs

public static long abs(long d)
Mimics Math.abs(double)


negate

public static long negate(long d)
Returns the negation of a double value. Special cases:

This method takes the place of the unary - operator.

Parameters:
d - the double value whose negated value is to be determined
Returns:
the negation of the argument.

eq

public 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. Special cases:

This method takes the place of the == operator.

Parameters:
d1 - the first double value to be compared.
d2 - the second double value to be compared.
Returns:
true if the two values are considered equal; false otherwise.

ne

public 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. Special cases: The value returned by ne is always the opposite of the value returned by eq for the same arguments.

This method takes the place of the != operator.

Parameters:
d1 - the first double value to be compared.
d2 - the second double value to be compared.
Returns:
true if the two values are considered equal; false otherwise.

lt

public 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. Special cases:

This method takes the place of the < operator.

Parameters:
d1 - the first double value to be compared.
d2 - the second double value to be compared.
Returns:
true if the first value is less than the second value; false otherwise.

le

public 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. Special cases:

This method takes the place of the <= operator.

Parameters:
d1 - the first double value to be compared.
d2 - the second double value to be compared.
Returns:
true if the first value is less than or equal to the second value; false otherwise.

gt

public 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. Special cases:

This method takes the place of the > operator.

Parameters:
d1 - the first double value to be compared.
d2 - the second double value to be compared.
Returns:
true if the first value is greater than the second value; false otherwise.

ge

public 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. Special cases:

This method takes the place of the >= operator.

Parameters:
d1 - the first double value to be compared.
d2 - the second double value to be compared.
Returns:
true if the first value is greater than or equal to the second value; false otherwise.

compare

public static int compare(long d1,
                          long d2)
Mimics Double.compare(double, double).

Note that when using this method (as well as Double.compare), the following rules apply:


max

public static long max(long d1,
                       long d2)
Mimics Math.max(double, double)


min

public static long min(long d1,
                       long d2)
Mimics Math.min(double, double)


intToDouble

public 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. This is a widening primitive conversion which will result in neither a loss of magnitude nor precision.

Parameters:
x - the int to be converted
Returns:
the double representation of the argument

longToDouble

public 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. This is a widening primitive conversion which will not result in a loss of magnitude, but might result in a loss of precision.

Parameters:
x - the long to be converted
Returns:
the double representation of the argument

floatToDouble

public 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. This is a widening primitive conversion which will result in neither a loss of magnitude nor precision.

Parameters:
f - the float to be converted
Returns:
the double representation of the argument

byteValue

public 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. 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.

Parameters:
d - the double to be converted
Returns:
the byte representation of the argument

shortValue

public 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. 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.

Parameters:
d - the double to be converted
Returns:
the short representation of the argument

intValue

public 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. This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Parameters:
d - the double to be converted
Returns:
the int representation of the argument

longValue

public 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. This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Parameters:
d - the double to be converted
Returns:
the long representation of the argument

floatValue

public 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. This is a narrowing primitive conversion which may result in a loss of magnitude and/or precision.

Parameters:
d - the double to be converted
Returns:
the float representation of the argument

random

public static long random()
Mimics Math.random()


add

public static long add(long d1,
                       long d2)
Returns the sum of the two double arguments according to section 15.18.2 of the JLS.

This method takes the place of the + operator.

Parameters:
d1 - the first double value to be summed.
d2 - the second double value to be summed.
Returns:
the sum of the two arguments

sub

public static long sub(long d1,
                       long d2)
Returns the difference of the two double arguments according to section 15.18.2 of the JLS.

This method takes the place of the binary - operator.

Parameters:
d1 - the first double value
d2 - the second double value
Returns:
the difference of the two arguments

mul

public static long mul(long d1,
                       long d2)
Returns the product of the two double arguments according to section 15.17.1 of the JLS.

This method takes the place of the * operator.

Parameters:
d1 - the first double value
d2 - the second double value
Returns:
the product of the two arguments

div

public static long div(long d1,
                       long d2)
Returns the quotient of the two double arguments according to section 15.17.2 of the JLS.

This method takes the place of the / operator.

Parameters:
d1 - the double dividend
d2 - the double divisor
Returns:
the quotient of the two arguments

mod

public static long mod(long d1,
                       long d2)
Returns the remainder of the two double arguments according to section 15.17.3 of the JLS.

This method takes the place of the % operator.

Parameters:
d1 - the double dividend
d2 - the double divisor
Returns:
the remainder of the two arguments
See Also:
IEEEremainder(long, long)

truncate

public 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. Special cases:

Parameters:
d - a double value.
Returns:
the double of greatest magnitude (furthest from zero) whose magnitude is not greater than the argument's and which is equal to a mathematical integer.

rint

public static long rint(long d)
Mimics Math.rint(double).


floor

public static long floor(long d)
Mimics Math.floor(double).


ceil

public static long ceil(long d)
Mimcs Math.ceil(double).


round

public static long round(long d)
Mimcs Math.round(double).


parseDouble

public static long parseDouble(java.lang.String s)
Mimics Double.parseDouble(String).

See the notes on toString for some caveats on String conversion.

Throws:
java.lang.NumberFormatException - if the string does not contain a parsable number.
See Also:
toString(long)

toString

public static java.lang.String toString(long d)
Mimics Double.toString(double).

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.


toString

public 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).

Parameters:
d - the double to be converted.
maxStringLength - the maximum length of the returned string
Returns:
a string representation of the argument.
See Also:
toString(long)

toDegrees

public static long toDegrees(long angrad)
Mimics Math.toDegrees(double).


toRadians

public static long toRadians(long angdeg)
Mimics Math.toRadians(double).


toGradians

public static long toGradians(long angrad)

gradiansToRadians

public static long gradiansToRadians(long anggrad)

scalbn

public 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. Note that the second argument is really an int, not a float or double.

Parameters:
d - a double value.
n - an int value.
Returns:
the value d * 2n.

IEEEremainder

public static long IEEEremainder(long d1,
                                 long d2)
Mimics Math.IEEEremainder(double, double).


sqrt

public static long sqrt(long d)
Mimics Math.sqrt(double).


exp

public static long exp(long d)
Mimics Math.exp(double).


expm1

public 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.

Parameters:
d - the exponent to raise e to.
Returns:
the value ed - 1, where e is the base of the natural logarithms.
See Also:
exp(long), log1p(long)

pow

public static long pow(long d1,
                       long d2)
Mimics Math.pow(double, double).


log

public static long log(long d,
                       long base)
Returns the logarithm of a 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.

Parameters:
d - a double value greater than 0.0.
base - a double value greater than 0.0.
Returns:
the value logbase d

log10

public static long log10(long d)
Returns the base 10 logarithm of a double value.

Parameters:
d - a double value greater than 0.0.
Returns:
the value log10 d

log

public static long log(long d)
Mimics Math.log(double).


log1p

public 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.

Parameters:
d - a double value greater than -1.0.
Returns:
the value ln d, the natural logarithm of d + 1.
See Also:
log(long), expm1(long)

sin

public static long sin(long d)
Mimics Math.sin(double).


cos

public static long cos(long d)
Mimics Math.cos(double).


tan

public static long tan(long d)
Mimics Math.tan(double).


asin

public static final long asin(long d)
Mimics Math.asin(double).


acos

public static long acos(long d)
Mimics Math.acos(double).


atan

public static long atan(long d)
Mimics Math.atan(double).


cosh

public static long cosh(long d)
Returns the hyperbolic cosine of an angle.

Parameters:
d - an angle, in radians.
Returns:
the hyperbolic cosine of the argument.

sinh

public static long sinh(long d)
Returns the hyperbolic sine of an angle.

Parameters:
d - an angle, in radians.
Returns:
the hyperbolic sine of the argument.

tanh

public static long tanh(long d)
Returns the hyperbolic tangent of an angle.

Parameters:
d - an angle, in radians.
Returns:
the hyperbolic tangent of the argument.

acosh

public static long acosh(long d)
Returns the arc hyperbolic cosine of an angle.

Parameters:
d - the value whose arc hyperbolic cosine is to be returned.
Returns:
the arc hyperbolic cosine of the argument.

asinh

public static long asinh(long d)
Returns the arc hyperbolic sine of an angle.

Parameters:
d - the value whose arc hyperbolic sine is to be returned.
Returns:
the arc hyperbolic sine of the argument.

atanh

public static long atanh(long d)
Returns the arc hyperbolic tangent of an angle.

Parameters:
d - the value whose arc hyperbolic tangent is to be returned.
Returns:
the arc hyperbolic tangent of the argument.

percentChange

public static long percentChange(long d1,
                                 long d2)
Returns the difference of d2 and d1, expressed as a percentage of d1.

Parameters:
d1 - the "starting" value
d2 - the "final" value
Returns:
100 * ((d2 - d1) / d1)

percentTotal

public static long percentTotal(long d1,
                                long d2)
Returns d2 expressed as a percentage of d1

Parameters:
d1 - the "base" value
d2 - the other value
Returns:
100 * (d2 / d1)

factorial

public static long factorial(long d)
Returns the factorial of d. If d is not a mathematical integer greater than or equal to zero, the return value is NaN. Use the gamma function for non-integer values.

This is a naive implentation. TODO: make this better.

Parameters:
d - a double value.
Returns:
d!

permutations

public 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. If d1 and d2 are not mathematical integers than or equal to zero, or if d1 is less than d2, the return value is NaN.

Parameters:
d1 - a double value
d2 - a double value
Returns:
d1! / (d1 - d2)!
See Also:
factorial(long), combinations(long, long)

combinations

public 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. Also known as the binomial coefficient. If d1 and d2 are not mathematical integers greater than or equal to zero, or if d1 is less than d2, the return value is NaN.

Parameters:
d1 - a double value
d2 - a double value
Returns:
d1! / (d2! * (d1 - d2)!)
See Also:
factorial(long), permutations(long, long)

gamma

public static long gamma(long d)
Returns the complete gamma function of d.

Parameters:
d - a double value
Returns:
Gamma(d)
See Also:
lgamma(long)

lgamma

public static long lgamma(long d)
Returns the natural logarithm of the absolute value of the gamma function of d.

Parameters:
d - a double value
Returns:
Log(|Gamma(d)|)
See Also:
gamma(long)

doubleValue

public long doubleValue()
Returns the double value of this MicroDouble object.


toString

public java.lang.String toString()
Returns a String object representing this MicroDouble's value. Equivalent to toString(doubleValue()).

Overrides:
toString in class java.lang.Object
See Also:
toString(long)

hashCode

public int hashCode()
Returns a hash code for this MicroDouble object. Equivalent to (int) (doubleValue() ^ (doubleValue >>> 32))

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Compares this object against the specified object. Equivalent to ((obj instanceof MicroDouble) && (compare(((MicroDouble) obj).doubleValue(), doubleValue()) == 0))

Overrides:
equals in class java.lang.Object
See Also:
compare(long, long)