# Class DoubleApfloatImpl

java.lang.Object
org.apfloat.internal.DoubleBaseMath
org.apfloat.internal.DoubleApfloatImpl

All Implemented Interfaces:
  `Serializable, ApfloatImpl`

public class DoubleApfloatImpl extends DoubleBaseMath implements ApfloatImpl
Immutable apfloat implementation class for the `double` data element type.

The associated `DataStorage` is assumed to be immutable also. This way performance can be improved by sharing the data storage between different `ApfloatImpl`'s and by only varying the `ApfloatImpl` specific fields, like sign, precision and exponent.

This implementation doesn't necessarily store any extra digits for added precision, so the last digit of any operation may be inaccurate.

Version:
  1.16.0
Author:
  Mikko Tommila
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DoubleApfloatImpl(double value, long precision, int radix)`
  Create a new `DoubleApfloatImpl` instance from a `double`.
  `DoubleApfloatImpl(long value, long precision, int radix)`
  Create a new `DoubleApfloatImpl` instance from a `long`.
  `DoubleApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger)`
  Create a new `DoubleApfloatImpl` instance reading from a stream.
  `DoubleApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger, long initialSize)`
  Create a new `DoubleApfloatImpl` instance reading from a stream.
  `DoubleApfloatImpl(String value, long precision, int radix, boolean isInteger)`
  Create a new `DoubleApfloatImpl` instance from a String.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ApfloatImpl`
  `absCeil()`
  Returns this `ApfloatImpl` rounded away from zero.
  `ApfloatImpl`
  `absFloor()`
  Returns this `ApfloatImpl` rounded towards zero.
  `ApfloatImpl`
  `addAll(ApfloatImpl... x)`
  Add numbers together.
  `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.
  `boolean`
  `equals(Object obj)`
  Compares this object to the specified object.
  `ApfloatImpl`
  `frac()`
  Returns the fractional part of this `ApfloatImpl`.
  `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`
  `modShort(ApfloatImpl x)`
  Return the remainder when this `ApfloatImpl` is divided by an `ApfloatImpl` that is "short".
  `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`.
  `long`
  `size()`
  Returns the size of the mantissa of this `ApfloatImpl`.
  `Reader`
  `toReader(boolean pretty)`
  Return a Reader from which the string representation of this `ApfloatImpl` can be read.
  `String`
  `toString(boolean pretty)`
  Convert this `ApfloatImpl` to `String`.
  `void`
  `writeTo(Writer out, boolean pretty)`
  Print this `ApfloatImpl` to a Writer.

  ### Methods inherited from class DoubleBaseMath

  `baseAdd, baseDivide, baseMultiplyAdd, baseSubtract`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DoubleApfloatImpl

    public DoubleApfloatImpl(String value, long precision, int radix, boolean isInteger) throws NumberFormatException, ApfloatRuntimeException
    Create a new `DoubleApfloatImpl` instance from a String.
    Parameters:
      `value` - The string to be parsed to a number.
      `precision` - The precision of the number (in digits of the radix).
      `radix` - The radix in which the number is created.
      `isInteger` - Specifies if the number to be parsed from the string is to be treated as an integer or not.
    Throws:
      `NumberFormatException` - If the number is not valid.
      `ApfloatRuntimeException`

  - ### DoubleApfloatImpl

    public DoubleApfloatImpl(long value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException
    Create a new `DoubleApfloatImpl` instance from a `long`.
    Parameters:
      `value` - The value of the number.
      `precision` - The precision of the number (in digits of the radix).
      `radix` - The radix in which the number is created.
    Throws:
      `NumberFormatException` - If the number is not valid.
      `ApfloatRuntimeException`

  - ### DoubleApfloatImpl

    public DoubleApfloatImpl(double value, long precision, int radix) throws NumberFormatException, ApfloatRuntimeException
    Create a new `DoubleApfloatImpl` instance from a `double`.
    Parameters:
      `value` - The value of the number.
      `precision` - The precision of the number (in digits of the radix).
      `radix` - The radix in which the number is created.
    Throws:
      `NumberFormatException` - If the number is not valid.
      `ApfloatRuntimeException`

  - ### DoubleApfloatImpl

    public DoubleApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger) throws IOException, NumberFormatException, ApfloatRuntimeException
    Create a new `DoubleApfloatImpl` instance reading from a stream.

    Implementation note: this constructor calls the `in` stream's single-character `read()` method. If the underlying stream doesn't explicitly implement this method in some efficient way, but simply inherits it from the `Reader` base class, performance will suffer as the default `Reader` method creates a `new char[1]` on every call to `read()`.

    Parameters:
      `in` - The stream to read from.
      `precision` - The precision of the number (in digits of the radix).
      `radix` - The radix in which the number is created.
      `isInteger` - Specifies if the number to be parsed from the stream is to be treated as an integer or not.
    Throws:
      `IOException` - If an I/O error occurs accessing the stream.
      `NumberFormatException` - If the number is not valid.
      `ApfloatRuntimeException`

  - ### DoubleApfloatImpl

    public DoubleApfloatImpl(PushbackReader in, long precision, int radix, boolean isInteger, long initialSize) throws IOException, NumberFormatException, ApfloatRuntimeException
    Create a new `DoubleApfloatImpl` instance reading from a stream. A hint for the size of the number can be specified.

    Implementation note: this constructor calls the `in` stream's single-character `read()` method. If the underlying stream doesn't explicitly implement this method in some efficient way, but simply inherits it from the `Reader` base class, performance will suffer as the default `Reader` method creates a `new char[1]` on every call to `read()`.

    Parameters:
      `in` - The stream to read from.
      `precision` - The precision of the number (in digits of the radix).
      `radix` - The radix in which the number is created.
      `isInteger` - Specifies if the number to be parsed from the stream is to be treated as an integer or not.
      `initialSize` - The initially allocated size (in digits of the radix) for the number.
    Throws:
      `IOException` - If an I/O error occurs accessing the stream.
      `NumberFormatException` - If the number is not valid.
      `ApfloatRuntimeException`
    Since:
      1.16.0

- ## Method Details

  - ### addOrSubtract

    public ApfloatImpl addOrSubtract(ApfloatImpl x, boolean subtract) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Add or subtract an `ApfloatImpl` to this object.
    Specified by:
      `addOrSubtract` in interface `ApfloatImpl`
    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`

  - ### addAll

    public ApfloatImpl addAll(ApfloatImpl... x) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Add numbers together.
    Specified by:
      `addAll` in interface `ApfloatImpl`
    Parameters:
      `x` - The numbers to be added to this number.
    Returns:
      The sum.
    Throws:
      `ApfloatRuntimeException`

  - ### multiply

    public ApfloatImpl multiply(ApfloatImpl x) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Multiply this object by an `ApfloatImpl`.
    Specified by:
      `multiply` in interface `ApfloatImpl`
    Parameters:
      `x` - The number to be multiplied by this `ApfloatImpl`.
    Returns:
      `this * x`.
    Throws:
      `ApfloatRuntimeException`

  - ### isShort

    public boolean isShort() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    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.

    Specified by:
      `isShort` in interface `ApfloatImpl`
    Returns:
      `true` if the `ApfloatImpl` is "short", `false` if not.
    Throws:
      `ApfloatRuntimeException`
    See Also:
      - `Apfloat.isShort()`

  - ### divideShort

    public ApfloatImpl divideShort(ApfloatImpl x) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Divide this `ApfloatImpl` by an `ApfloatImpl` that is "short".
    Specified by:
      `divideShort` in interface `ApfloatImpl`
    Parameters:
      `x` - The number by which this `ApfloatImpl` is to be divided.
    Returns:
      `this / x`.
    Throws:
      `ApfloatRuntimeException`

  - ### modShort

    public ApfloatImpl modShort(ApfloatImpl x) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Return the remainder when this `ApfloatImpl` is divided by an `ApfloatImpl` that is "short".
    Specified by:
      `modShort` in interface `ApfloatImpl`
    Parameters:
      `x` - The modulus.
    Returns:
      `this % x`.
    Throws:
      `ApfloatRuntimeException`

  - ### absFloor

    public ApfloatImpl absFloor() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Returns this `ApfloatImpl` rounded towards zero.
    Specified by:
      `absFloor` in interface `ApfloatImpl`
    Returns:
      This `ApfloatImpl` rounded towards zero.
    Throws:
      `ApfloatRuntimeException`

  - ### absCeil

    public ApfloatImpl absCeil() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Returns this `ApfloatImpl` rounded away from zero.
    Specified by:
      `absCeil` in interface `ApfloatImpl`
    Returns:
      This `ApfloatImpl` rounded away from zero.
    Throws:
      `ApfloatRuntimeException`

  - ### frac

    public ApfloatImpl frac() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Returns the fractional part of this `ApfloatImpl`.
    Specified by:
      `frac` in interface `ApfloatImpl`
    Returns:
      The fractional part of this `ApfloatImpl`.
    Throws:
      `ApfloatRuntimeException`

  - ### radix

    public int radix()
    Description copied from interface: `ApfloatImpl`
    Returns the radix of this `ApfloatImpl`.
    Specified by:
      `radix` in interface `ApfloatImpl`
    Returns:
      The radix of this `ApfloatImpl`.

  - ### precision

    public long precision()
    Description copied from interface: `ApfloatImpl`
    Returns the precision of this `ApfloatImpl`.
    Specified by:
      `precision` in interface `ApfloatImpl`
    Returns:
      The precision of this `ApfloatImpl`.

  - ### size

    public long size() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Returns the size of the mantissa of this `ApfloatImpl`.
    Specified by:
      `size` in interface `ApfloatImpl`
    Returns:
      The size of the mantissa of this `ApfloatImpl`.
    Throws:
      `ApfloatRuntimeException`

  - ### precision

    public ApfloatImpl precision(long precision)
    Description copied from interface: `ApfloatImpl`
    Returns this `ApfloatImpl` with the specified precision.
    Specified by:
      `precision` in interface `ApfloatImpl`
    Parameters:
      `precision` - The precision.
    Returns:
      This `ApfloatImpl` with the specified precision.

  - ### scale

    public long scale() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Returns the scale of this `ApfloatImpl`.
    Specified by:
      `scale` in interface `ApfloatImpl`
    Returns:
      The scale of this `ApfloatImpl`.
    Throws:
      `ApfloatRuntimeException`
    See Also:
      - `Apfloat.scale()`

  - ### signum

    public int signum()
    Description copied from interface: `ApfloatImpl`
    Returns the signum of this `ApfloatImpl`.
    Specified by:
      `signum` in interface `ApfloatImpl`
    Returns:
      The signum of this `ApfloatImpl`.
    See Also:
      - `Apfloat.signum()`

  - ### negate

    public ApfloatImpl negate() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Returns this `ApfloatImpl` negated.
    Specified by:
      `negate` in interface `ApfloatImpl`
    Returns:
      `-this`.
    Throws:
      `ApfloatRuntimeException`

  - ### doubleValue

    public double doubleValue()
    Description copied from interface: `ApfloatImpl`
    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.

    Specified by:
      `doubleValue` in interface `ApfloatImpl`
    Returns:
      The numeric value represented by this object after conversion to type `double`.

  - ### longValue

    public long longValue()
    Description copied from interface: `ApfloatImpl`
    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.

    Specified by:
      `longValue` in interface `ApfloatImpl`
    Returns:
      The numeric value represented by this object after conversion to type `long`.

  - ### isOne

    public boolean isOne() throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Tests if this number is equal to 1.
    Specified by:
      `isOne` in interface `ApfloatImpl`
    Returns:
      `true` if this number is equal to one, otherwise `false`.
    Throws:
      `ApfloatRuntimeException`

  - ### equalDigits

    public long equalDigits(ApfloatImpl x) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    The number of equal digits in this `ApfloatImpl` and another number.
    Specified by:
      `equalDigits` in interface `ApfloatImpl`
    Parameters:
      `x` - The number to compare with.
    Returns:
      The number of equal digits in this `ApfloatImpl` and `x`.
    Throws:
      `ApfloatRuntimeException`
    See Also:
      - `Apfloat.equalDigits(org.apfloat.Apfloat)`

  - ### compareTo

    public int compareTo(ApfloatImpl x) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Compare this `ApfloatImpl` and another number.
    Specified by:
      `compareTo` in interface `ApfloatImpl`
    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(org.apfloat.Apfloat)`

  - ### equals

    public boolean equals(Object obj)
    Compares this object to the specified object.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - The object to compare with.
    Returns:
      `true` if the objects are equal; `false` otherwise.

  - ### hashCode

    public int hashCode()
    Description copied from interface: `ApfloatImpl`
    Returns the hash code for this `ApfloatImpl`.
    Specified by:
      `hashCode` in interface `ApfloatImpl`
    Overrides:
      `hashCode` in class `Object`
    Returns:
      The hash code for this `ApfloatImpl`.

  - ### toString

    public String toString(boolean pretty) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Convert this `ApfloatImpl` to `String`.
    Specified by:
      `toString` in interface `ApfloatImpl`
    Parameters:
      `pretty` - Flag for formatting.
    Returns:
      String representation of this `ApfloatImpl`.
    Throws:
      `ApfloatRuntimeException`
    See Also:
      - `Apfloat.toString(boolean)`

  - ### toReader

    public Reader toReader(boolean pretty) throws ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Return a Reader from which the string representation of this `ApfloatImpl` can be read.
    Specified by:
      `toReader` in interface `ApfloatImpl`
    Parameters:
      `pretty` - Flag for formatting.
    Returns:
      Reader for the string representation of this `ApfloatImpl`.
    Throws:
      `ApfloatRuntimeException`

  - ### writeTo

    public void writeTo(Writer out, boolean pretty) throws IOException, ApfloatRuntimeException
    Description copied from interface: `ApfloatImpl`
    Print this `ApfloatImpl` to a Writer.
    Specified by:
      `writeTo` in interface `ApfloatImpl`
    Parameters:
      `out` - The stream to write to.
      `pretty` - Flag for formatting.
    Throws:
      `IOException` - In case of I/O error writing to the Writer.
      `ApfloatRuntimeException`
    See Also:
      - `Apfloat.writeTo(Writer,boolean)`