# Interface AdditionStrategy<T>

Type Parameters:
  `T` - The element type of the addition strategy.

All Known Implementing Classes:
  `DoubleAdditionStrategy, FloatAdditionStrategy, IntAdditionStrategy, LongAdditionStrategy`

public interface AdditionStrategy<T>
Generic addition strategy. Also subtraction, "short" multiplication and "short" division can be done.

Since:
  1.7.0
Version:
  1.15.0
Author:
  Mikko Tommila

- ## Method Summary

  Modifier and Type
  Method
  Description
  `T`
  `add(DataStorage.Iterator src1, DataStorage.Iterator src2, T carry, DataStorage.Iterator dst, long size)`
  Addition in some base.
  `T`
  `divide(DataStorage.Iterator src1, T src2, T carry, DataStorage.Iterator dst, long size)`
  Division in some base.
  `T`
  `multiplyAdd(DataStorage.Iterator src1, DataStorage.Iterator src2, T src3, T carry, DataStorage.Iterator dst, long size)`
  Multiplication and addition in some base.
  `T`
  `subtract(DataStorage.Iterator src1, DataStorage.Iterator src2, T carry, DataStorage.Iterator dst, long size)`
  Subtraction in some base.
  `T`
  `zero()`
  Returns the zero element.

- ## Method Details

  - ### add

    T add(DataStorage.Iterator src1, DataStorage.Iterator src2, T carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeException
    Addition in some base. Adds the data words of `src1` and `src2` and stores the result to `dst`. `src2` may be `null`, in which case it is ignored (only the carry is propagated).

    Essentially calculates `dst[i] = src1[i] + src2[i]`.

    Parameters:
      `src1` - First source data sequence. Can be `null`, in which case it's ignored.
      `src2` - Second source data sequence. Can be `null`, in which case it's ignored.
      `carry` - Input carry bit. This is added to the first (rightmost) word in the accessed sequence.
      `dst` - Destination data sequence.
      `size` - Number of elements to process.
    Returns:
      Overflow carry bit. Propagated carry bit from the addition of the last (leftmost) word in the accessed sequence.
    Throws:
      `ApfloatRuntimeException`

  - ### subtract

    T subtract(DataStorage.Iterator src1, DataStorage.Iterator src2, T carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeException
    Subtraction in some base. Subtracts the data words of `src1` and `src2` and stores the result to `dst`. `src1` and `src2` may be `null`, in which case they are ignored (the values are assumed to be zero and only the carry is propagated).

    Essentially calculates `dst[i] = src1[i] - src2[i]`.

    Parameters:
      `src1` - First source data sequence. Can be `null`, in which case the input values are assumed to be zero.
      `src2` - Second source data sequence. Can be `null`, in which case it's ignored, or can be the same as `dst`.
      `carry` - Input carry bit. This is subtracted from the first (rightmost) word in the accessed sequence.
      `dst` - Destination data sequence.
      `size` - Number of elements to process.
    Returns:
      Overflow carry bit. Propagated carry bit from the subtraction of the last (leftmost) word in the accessed sequence. The value is `1` if the carry is set, and `0` otherwise.
    Throws:
      `ApfloatRuntimeException`

  - ### multiplyAdd

    T multiplyAdd(DataStorage.Iterator src1, DataStorage.Iterator src2, T src3, T carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeException
    Multiplication and addition in some base. Multiplies the data words of `src1` by `src3` and adds the result to the words in `src2`, and stores the result to `dst`. `src2` may be `null`, in which case it is ignored (the values are assumed to be zero).

    Assumes that the result from the addition doesn't overflow the upper result word (to larger than the base). This is the case e.g. when using this method to perform an arbitrary precision multiplication.

    Essentially calculates `dst[i] = src1[i] * src3 + src2[i]`.

    Parameters:
      `src1` - First source data sequence.
      `src2` - Second source data sequence. Can be `null`, in which case it's ignored, or can be the same as `dst`.
      `src3` - Multiplicand. All elements of `src1` are multiplied by this value.
      `carry` - Input carry word. This is added to the first (rightmost) word in the accessed sequence.
      `dst` - Destination data sequence.
      `size` - Number of elements to process.
    Returns:
      Overflow carry word. Propagated carry word from the multiplication and addition of the last (leftmost) word in the accessed sequence.
    Throws:
      `ApfloatRuntimeException`

  - ### divide

    T divide(DataStorage.Iterator src1, T src2, T carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeException
    Division in some base. Divides the data words of `src1` by `src2` and stores the result to `dst`. `src1` may be `null`, in which case it is ignored (the values are assumed to be zero and only the carry division is propagated).

    Essentially calculates `dst[i] = src1[i] / src2`.

    Parameters:
      `src1` - First source data sequence. Can be `null`, in which case the input values are assumed to be zero.
      `src2` - Divisor. All elements of `src1` are divided by this value.
      `carry` - Input carry word. Used as the upper word for the division of the first input element. This should be the remainder word returned from the previous block processed.
      `dst` - Destination data sequence. Can be `null`, in which case only the remainder is computed.
      `size` - Number of elements to process.
    Returns:
      Remainder word of the propagated division of the last (rightmost) word in the accessed sequence.
    Throws:
      `ApfloatRuntimeException`

  - ### zero

    T zero()
    Returns the zero element.
    Returns:
      Zero of the correct element type.