Package org.apfloat.internal
Class IntBaseMath
java.lang.Object
org.apfloat.internal.IntBaseMath
 All Implemented Interfaces:
Serializable
 Direct Known Subclasses:
IntAdditionStrategy
,IntApfloatImpl
,IntCRTMath
,IntMediumConvolutionStrategy
,IntShortConvolutionStrategy
Mathematical operations on numbers in a base.
Implementation for the
int
type. Version:
 1.8.2
 Author:
 Mikko Tommila
 See Also:
 Serialized Form

Constructor Summary

Method Summary
Modifier and TypeMethodDescriptionint
baseAdd(DataStorage.Iterator src1, DataStorage.Iterator src2, int carry, DataStorage.Iterator dst, long size)
Addition in some base.int
baseDivide(DataStorage.Iterator src1, int src2, int carry, DataStorage.Iterator dst, long size)
Division in some base.int
baseMultiplyAdd(DataStorage.Iterator src1, DataStorage.Iterator src2, int src3, int carry, DataStorage.Iterator dst, long size)
Multiplication and addition in some base.int
baseSubtract(DataStorage.Iterator src1, DataStorage.Iterator src2, int carry, DataStorage.Iterator dst, long size)
Subtraction in some base.

Constructor Details

IntBaseMath
public IntBaseMath(int radix)Creates a base math using the specified radix. Parameters:
radix
 The radix that will be used.


Method Details

baseAdd
public int baseAdd(DataStorage.Iterator src1, DataStorage.Iterator src2, int carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeExceptionAddition in some base. Adds the data words ofsrc1
andsrc2
and stores the result todst
.src2
may benull
, 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 benull
, in which case it's ignored.src2
 Second source data sequence. Can benull
, 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

baseSubtract
public int baseSubtract(DataStorage.Iterator src1, DataStorage.Iterator src2, int carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeExceptionSubtraction in some base. Subtracts the data words ofsrc1
andsrc2
and stores the result todst
.src1
andsrc2
may benull
, 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 benull
, in which case the input values are assumed to be zero.src2
 Second source data sequence. Can benull
, in which case it's ignored, or can be the same asdst
.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, and0
otherwise.  Throws:
ApfloatRuntimeException

baseMultiplyAdd
public int baseMultiplyAdd(DataStorage.Iterator src1, DataStorage.Iterator src2, int src3, int carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeExceptionMultiplication and addition in some base. Multiplies the data words ofsrc1
bysrc3
and adds the result to the words insrc2
, and stores the result todst
.src2
may benull
, 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 benull
, in which case it's ignored, or can be the same asdst
.src3
 Multiplicand. All elements ofsrc1
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

baseDivide
public int baseDivide(DataStorage.Iterator src1, int src2, int carry, DataStorage.Iterator dst, long size) throws ApfloatRuntimeExceptionDivision in some base. Divides the data words ofsrc1
bysrc2
and stores the result todst
.src1
may benull
, 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 benull
, in which case the input values are assumed to be zero.src2
 Divisor. All elements ofsrc1
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.size
 Number of elements to process. Returns:
 Remainder word of the propagated division of the last (rightmost) word in the accessed sequence.
 Throws:
ApfloatRuntimeException
