Another floating point class. This one is built using radix 10000 which is 104, so its almost decimal.
The design goals here are:
Trade offs:
Numbers are represented in the following form:
n = sign × mant × (radix)exp;where sign is ±1, mantissa represents a fractional number between zero and one. mant[0] is the least significant digit. exp is in the range of -32767 to 32768
IEEE 854-1987 Notes and differences
IEEE 854 requires the radix to be either 2 or 10. The radix here is 10000, so that requirement is not met, but it is possible that a subclassed can be made to make it behave as a radix 10 number. It is my opinion that if it looks and behaves as a radix 10 number then it is one and that requirement would be met.
The radix of 10000 was chosen because it should be faster to operate on 4 decimal digits at once instead of one at a time. Radix 10 behavior can be realized by adding an additional rounding step to ensure that the number of decimal digits represented is constant.
The IEEE standard specifically leaves out internal data encoding, so it is reasonable to conclude that such a subclass of this radix 10000 system is merely an encoding of a radix 10 system.
IEEE 854 also specifies the existence of "sub-normal" numbers. This class does not contain any such entities. The most significant radix 10000 digit is always non-zero. Instead, we support "gradual underflow" by raising the underflow flag for numbers less with exponent less than expMin, but don't flush to zero until the exponent reaches MIN_EXP-digits. Thus the smallest number we can represent would be: 1E(-(MIN_EXP-digits-1)*4), eg, for digits=5, MIN_EXP=-32767, that would be 1e-131092.
IEEE 854 defines that the implied radix point lies just to the right of the most significant digit and to the left of the remaining digits. This implementation puts the implied radix point to the left of all digits including the most significant one. The most significant digit here is the one just to the right of the radix point. This is a fine detail and is really only a matter of definition. Any side effects of this can be rendered invisible by a subclass.
DfpField
| Modifier and Type | Field and Description |
|---|---|
| private static final String | ADD_TRAP
Name for traps triggered by addition. |
| private static final String | ALIGN_TRAP
Name for traps triggered by alignment. |
| private static final String | DIVIDE_TRAP
Name for traps triggered by division. |
| public static final int | ERR_SCALE
The amount under/overflows are scaled by before going to trap handler |
| protected int | exp
Exponent. |
| private final DfpField | field
Factory building similar Dfp's. |
| public static final byte | FINITE
Indicator value for normal finite numbers. |
| private static final String | GREATER_THAN_TRAP
Name for traps triggered by greaterThan. |
| public static final byte | INFINITE
Indicator value for Infinity. |
| private static final String | LESS_THAN_TRAP
Name for traps triggered by lessThan. |
| protected int[] | mant
Mantissa. |
| public static final int | MAX_EXP
The maximum exponent before overflow is signaled and results flushed to infinity |
| public static final int | MIN_EXP
The minimum exponent before underflow is signaled. |
| private static final String | MULTIPLY_TRAP
Name for traps triggered by multiplication. |
| private static final String | NAN_STRING
String for NaN representation. |
| protected byte | nans
Indicator for non-finite / non-number values. |
| private static final String | NEG_INFINITY_STRING
String for negative infinity representation. |
| private static final String | NEW_INSTANCE_TRAP
Name for traps triggered by newInstance. |
| private static final String | NEXT_AFTER_TRAP
Name for traps triggered by nextAfter. |
| private static final String | POS_INFINITY_STRING
String for positive infinity representation. |
| public static final byte | QNAN
Indicator value for quiet NaN. |
| public static final int | RADIX
The radix, or base of this system. |
| protected byte | sign
Sign bit: 1 for positive, -1 for negative. |
| public static final byte | SNAN
Indicator value for signaling NaN. |
| private static final String | SQRT_TRAP
Name for traps triggered by square root. |
| private static final String | TRUNC_TRAP
Name for traps triggered by truncation. |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | |
| protected | |
| protected | |
| protected | |
| public | |
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public Dfp | Returns: absolute value of instanceImplements org. Get the absolute value of instance. |
| public Dfp | |
| public Dfp | acosh()
Implements org. Inverse hyperbolic cosine operation. |
| public Dfp | Returns: sum of this and xnumber to add x)Implements org. Add x to this. |
| public Dfp | add(final double
right hand side parameter of the operator a)Implements org. '+' operator. |
| protected int | Returns: last digit destroyed by shifting rightdesired exponent e)Make our exp equal to the supplied one, this may cause rounding. |
| public Dfp | |
| public Dfp | asinh()
Implements org. Inverse hyperbolic sine operation. |
| public Dfp | |
| public Dfp | atan2(final Dfp
second argument of the arc tangent x)Implements org. Two arguments arc tangent operation. |
| public Dfp | atanh()
Implements org. Inverse hyperbolic tangent operation. |
| public Dfp | |
| public Dfp | Returns: rounded valueImplements org. Round to an integer using the round ceil mode. |
| public int | |
| private static int | |
| protected int | |
| public static Dfp | |
| public Dfp | copySign(final Dfp
the sign for the returned value s)Implements org. Returns the instance with the sign of the argument. |
| public Dfp | copySign(final double
the sign for the returned value s)Implements org. Returns the instance with the sign of the argument. |
| public Dfp | |
| public Dfp | |
| protected String | Returns: string representation of the instance in scientific notationConvert an instance to a string using scientific notation. |
| protected String | Returns: string representation of the instance in normal notationConvert an instance to a string using normal notation. |
| public Dfp | Returns: quotient of this by divisordivisor divisor)Implements org. Divide this by divisor. |
| public Dfp | Returns: quotient of this by divisordivisor divisor)Implements org. Divide by a single digit less than radix. |
| public Dfp | divide(final double
right hand side parameter of the operator a)Implements org. '÷' operator. |
| public Dfp | |
| public boolean | Returns: true if instance is equal to x and neither are NaN, false otherwiseobject to check instance against other)Overrides java. Check if instance is equal to x. |
| public Dfp | |
| public Dfp | |
| public Dfp | Returns: rounded valueImplements org. Round to an integer using the round floor mode. |
| public DfpField | |
| public Dfp | |
| public int | |
| public double | getReal()
Implements org. Get the real value of the number. |
| public Dfp | |
| public Dfp | |
| public boolean | Returns: true if instance is greater than x and neither are NaN, false otherwisenumber to check instance against x)Check if instance is greater than x. |
| public int | Returns: a hash code value for this objectOverrides java. Gets a hashCode for the instance. |
| public Dfp | hypot(final Dfp
a value y)Implements org. Returns the hypotenuse of a triangle with sides |
| public int | Returns: integer base 10 logarithmGet the exponent of the greatest power of 10 that is less than or equal to abs(this). |
| public int | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public Dfp | linearCombination(final Dfp[]
Factors. a, final Dfp[] Factors. b)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final double[]
Factors. a, final Dfp[] Factors. b)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final Dfp
first factor of the first term a1, final Dfp second factor of the first term b1, final Dfp first factor of the second term a2, final Dfp second factor of the second term b2)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final double
first factor of the first term a1, final Dfp second factor of the first term b1, final double first factor of the second term a2, final Dfp second factor of the second term b2)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final Dfp
first factor of the first term a1, final Dfp second factor of the first term b1, final Dfp first factor of the second term a2, final Dfp second factor of the second term b2, final Dfp first factor of the third term a3, final Dfp second factor of the third term b3)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final double
first factor of the first term a1, final Dfp second factor of the first term b1, final double first factor of the second term a2, final Dfp second factor of the second term b2, final double first factor of the third term a3, final Dfp second factor of the third term b3)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final Dfp
first factor of the first term a1, final Dfp second factor of the first term b1, final Dfp first factor of the second term a2, final Dfp second factor of the second term b2, final Dfp first factor of the third term a3, final Dfp second factor of the third term b3, final Dfp first factor of the third term a4, final Dfp second factor of the third term b4)Implements org. Compute a linear combination. |
| public Dfp | linearCombination(final double
first factor of the first term a1, final Dfp second factor of the first term b1, final double first factor of the second term a2, final Dfp second factor of the second term b2, final double first factor of the third term a3, final Dfp second factor of the third term b3, final double first factor of the third term a4, final Dfp second factor of the third term b4)Implements org. Compute a linear combination. |
| public Dfp | |
| public int | Returns: integer base 10 logarithm
Deprecated
as of 3.2, replaced by
intLog10(), in 4.0 the return type
will be changed to Dfp
Get the exponent of the greatest power of 10 that is less than or equal to abs(this). |
| public int | Returns: integer base 10000 logarithmGet the exponent of the greatest power of 10000 that is less than or equal to the absolute value of this. |
| public Dfp | |
| public Dfp | Returns: product of this and xmultiplicand x)Implements org. Multiply this by x. |
| public Dfp | Returns: product of this and xmultiplicand x)Implements org. Multiply this by a single digit x. |
| public Dfp | multiply(final double
right hand side parameter of the operator a)Implements org. '×' operator. |
| private Dfp | Returns: product of this and xmultiplicand x)Multiply this by a single digit 0<=x<radix. |
| public Dfp | Returns: the opposite of thisImplements org. Returns a number that is this number with the sign bit reversed. |
| public boolean | Returns: true if instance is not NaN and less than or equal to 0, false otherwiseCheck if instance is less than or equal to 0. |
| public Dfp | |
| public Dfp | Returns: a new instance with value xvalue to convert to an instance x)Create an instance from a byte value. |
| public Dfp | Returns: a new instance with value xvalue to convert to an instance x)Create an instance from an int value. |
| public Dfp | Returns: a new instance with value xvalue to convert to an instance x)Create an instance from a long value. |
| public Dfp | Returns: a new instance with value xvalue to convert to an instance x)Create an instance from a double value. |
| public Dfp | Returns: a new instance with the same value as dinstance to copy d)Create an instance by copying an existing one. |
| public Dfp | Returns: a new instance parsed from specified stringstring representation of the instance s)Create an instance from a String representation. |
| public Dfp | Returns: a new instance with a non-finite valuesign of the Dfp to create sig, final byte code)Creates an instance with a non-finite value. |
| public Dfp | |
| public boolean | Returns: true if instance is not NaN and greater than or equal to 0, false otherwiseCheck if instance is greater than or equal to 0. |
| public Dfp | pow(final double
power to apply p)Implements org. Power operation. |
| public Dfp | pow(final int
power to apply n)Implements org. Integer power operation. |
| public Dfp | |
| public Dfp | |
| public Dfp | |
| public Dfp | reciprocal()
Implements org. Returns the multiplicative inverse of |
| public Dfp | Returns: this less n × d, where n is the integer closest to this/ddivisor d)Implements org. Returns the IEEE remainder. |
| public Dfp | remainder(final double
right hand side parameter of the operator a)Implements org. IEEE remainder operator. |
| public Dfp | Returns: rounded valueImplements org. Round to nearest integer using the round-half-even method. |
| public Dfp | rootN(final int
order of the root n)Implements org. Nth root. |
| protected int | Returns: the IEEE flag if an exception occurred??? n)Round this given the next digit n using the current rounding mode. |
| public long | round()
Implements org. Get the closest long to instance value. |
| public Dfp | scalb(final int
power of 2 n)Implements org. Multiply the instance by a power of 2. |
| protected void | |
| protected void | |
| public Dfp | signum()
Implements org. Compute the signum of the instance. |
| public Dfp | |
| public Dfp | |
| public Dfp | Returns: square root of the instanceImplements org. Compute the square root. |
| public boolean | Returns: true if instance is not NaN and less than or equal to 0, false otherwiseCheck if instance is strictly less than 0. |
| public boolean | Returns: true if instance is not NaN and greater than or equal to 0, false otherwiseCheck if instance is strictly greater than 0. |
| public Dfp | Returns: difference of this and anumber to subtract x)Implements org. Subtract x from this. |
| public Dfp | subtract(final double
right hand side parameter of the operator a)Implements org. '-' operator. |
| public Dfp | |
| public Dfp | |
| public double | |
| public double[] | Returns: an array of two doubles which sum represent the instanceConvert the instance into a split double. |
| public String | Returns: string representation of the instanceOverrides java. Get a string representation of the instance. |
| protected Dfp | Returns: the value that should be return by the operation triggering the trapThe exception type - e.g. FLAG_OVERFLOW type, String The name of the routine we were in e.g. divide() what, Dfp An operand to this function if any oper, Dfp The default return value if trap not enabled def, Dfp The result that is specified to be delivered per
IEEE 854, if any result)Trap handler. |
| protected Dfp | Returns: truncated valuerounding mode to use rmodeDoes the integer conversions with the specified rounding. |
| public boolean |