org.apfloat.spi
Interface ApfloatImpl

All Superinterfaces:
Serializable
All Known Implementing Classes:
DoubleApfloatImpl, FloatApfloatImpl, IntApfloatImpl, LongApfloatImpl

public interface ApfloatImpl
extends Serializable

Interface for apfloat implementations. An ApfloatImpl implements all of the low-level functionality that is needed behind the high-level apfloat API.

A class implementing ApfloatImpl is not required to accept any other ApfloatImpl class as the argument than the same implementing class.

Version:
1.0
Author:
Mikko Tommila

Method Summary
 ApfloatImpl absCeil()
          Returns this ApfloatImpl rounded away from zero.
 ApfloatImpl absFloor()
          Returns this ApfloatImpl rounded towards zero.
 ApfloatImpl addOrSubtract(ApfloatImpl x, boolean subtract)
          Add or subtract an ApfloatImpl to this object.
 int compareTo(ApfloatImpl x)
          Compare this ApfloatImpl and another number.
 ApfloatImpl divideShort(ApfloatImpl x)
          Divide this ApfloatImpl by an ApfloatImpl that is "short".
 double doubleValue()
          Returns the value of the this number as a double.
 long equalDigits(ApfloatImpl x)
          The number of equal digits in this ApfloatImpl and another number.
 int hashCode()
          Returns the hash code for this ApfloatImpl.
 boolean isOne()
          Tests if this number is equal to 1.
 boolean isShort()
          Returns if this ApfloatImpl is "short".
 long longValue()
          Returns the value of the this number as a long.
 ApfloatImpl multiply(ApfloatImpl x)
          Multiply this object by an ApfloatImpl.
 ApfloatImpl negate()
          Returns this ApfloatImpl negated.
 long precision()
          Returns the precision of this ApfloatImpl.
 ApfloatImpl precision(long precision)
          Returns this ApfloatImpl with the specified precision.
 int radix()
          Returns the radix of this ApfloatImpl.
 long scale()
          Returns the scale of this ApfloatImpl.
 int signum()
          Returns the signum of this ApfloatImpl.
 String toString(boolean pretty)
          Convert this ApfloatImpl to String.
 void writeTo(Writer out, boolean pretty)
          Print this ApfloatImpl to a stream.
 

Method Detail

addOrSubtract

public ApfloatImpl addOrSubtract(ApfloatImpl x,
                                 boolean subtract)
                          throws ApfloatRuntimeException
Add or subtract an ApfloatImpl to this object.

Parameters:
x - The number to be added or subtracted to this ApfloatImpl.
subtract - true if the numbers are to be subtracted, false if added.
Returns:
this + x or this - x depending on the subtract argument.
Throws:
ApfloatRuntimeException

multiply

public ApfloatImpl multiply(ApfloatImpl x)
                     throws ApfloatRuntimeException
Multiply this object by an ApfloatImpl.

Parameters:
x - The number to be multiplied by this ApfloatImpl.
Returns:
this * x.
Throws:
ApfloatRuntimeException

isShort

public boolean isShort()
                throws ApfloatRuntimeException
Returns if this ApfloatImpl is "short". Typically ApfloatImpl is "short" if its mantissa fits in one machine word. If the apfloat is "short", some algorithms can be performed faster.

The return value of this method is highly implementation dependent.

Returns:
true if the ApfloatImpl is "short", false if not.
Throws:
ApfloatRuntimeException
See Also:
Apfloat.isShort()

divideShort

public ApfloatImpl divideShort(ApfloatImpl x)
                        throws ApfloatRuntimeException
Divide this ApfloatImpl by an ApfloatImpl that is "short".

Parameters:
x - The number by which this ApfloatImpl is to be divided.
Returns:
this / x.
Throws:
ApfloatRuntimeException

absFloor

public ApfloatImpl absFloor()
                     throws ApfloatRuntimeException
Returns this ApfloatImpl rounded towards zero.

Returns:
This ApfloatImpl rounded towards zero.
Throws:
ApfloatRuntimeException

absCeil

public ApfloatImpl absCeil()
                    throws ApfloatRuntimeException
Returns this ApfloatImpl rounded away from zero.

Returns:
This ApfloatImpl rounded away from zero.
Throws:
ApfloatRuntimeException

radix

public int radix()
Returns the radix of this ApfloatImpl.

Returns:
The radix of this ApfloatImpl.

precision

public long precision()
Returns the precision of this ApfloatImpl.

Returns:
The precision of this ApfloatImpl.

precision

public ApfloatImpl precision(long precision)
                      throws ApfloatRuntimeException
Returns this ApfloatImpl with the specified precision.

Parameters:
precision - The precision.
Returns:
This ApfloatImpl with the specified precision.
Throws:
ApfloatRuntimeException

scale

public long scale()
           throws ApfloatRuntimeException
Returns the scale of this ApfloatImpl.

Returns:
The scale of this ApfloatImpl.
Throws:
ApfloatRuntimeException
See Also:
Apfloat.scale()

signum

public int signum()
Returns the signum of this ApfloatImpl.

Returns:
The signum of this ApfloatImpl.
See Also:
Apfloat.signum()

negate

public ApfloatImpl negate()
                   throws ApfloatRuntimeException
Returns this ApfloatImpl negated.

Returns:
-this.
Throws:
ApfloatRuntimeException

doubleValue

public double doubleValue()
Returns the value of the this number as a double. If the number is greater than Double.MAX_VALUE, then Double.POSITIVE_INFINITY is returned.

If the number is less than Double.MIN_VALUE, then Double.NEGATIVE_INFINITY is returned.

If the number is very small in magnitude, underflow may happen and zero is returned.

Returns:
The numeric value represented by this object after conversion to type double.

longValue

public long longValue()
Returns the value of the this number as a long. The fractional part is truncated towards zero.

If the number is greater than Long.MAX_VALUE, then Long.MAX_VALUE is returned.

If the number is less than Long.MIN_VALUE, then Long.MIN_VALUE is returned.

Returns:
The numeric value represented by this object after conversion to type long.

isOne

public boolean isOne()
Tests if this number is equal to 1.

Returns:
true if this number is equal to one, otherwise false.

equalDigits

public long equalDigits(ApfloatImpl x)
                 throws ApfloatRuntimeException
The number of equal digits in this ApfloatImpl and another number.

Parameters:
x - The number to compare with.
Returns:
The number of equal digits in this ApfloatImpl and x.
Throws:
ApfloatRuntimeException
See Also:
Apfloat.equalDigits(Apfloat)

compareTo

public int compareTo(ApfloatImpl x)
              throws ApfloatRuntimeException
Compare this ApfloatImpl and another number.

Parameters:
x - The number to compare with.
Returns:
Zero, less than zero or greater than zero depending on the result of the comparison.
Throws:
ApfloatRuntimeException
See Also:
Apfloat.compareTo(Apfloat)

hashCode

public int hashCode()
Returns the hash code for this ApfloatImpl.

Returns:
The hash code for this ApfloatImpl.

toString

public String toString(boolean pretty)
                throws ApfloatRuntimeException
Convert this ApfloatImpl to String.

Parameters:
pretty - Flag for formatting.
Returns:
String representation of this ApfloatImpl.
Throws:
ApfloatRuntimeException
See Also:
Apfloat.toString(boolean)

writeTo

public void writeTo(Writer out,
                    boolean pretty)
             throws IOException,
                    ApfloatRuntimeException
Print this ApfloatImpl to a stream.

Parameters:
out - The stream to write to.
pretty - Flag for formatting.
Throws:
IOException - In case of I/O error writing to the stream.
ApfloatRuntimeException
See Also:
Apfloat.writeTo(Writer,boolean)