Class OceanusNewDecimal
java.lang.Object
io.github.tonywasher.joceanus.oceanus.decimal.OceanusNewDecimal
Decimal class performing integer arithmetic on large decimals.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOceanusNewDecimal(int pScale) Constructor.OceanusNewDecimal(long pIntegral, int pFractional, int pSign, int pScale) Constructor.OceanusNewDecimal(BigDecimal pSource) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(OceanusNewDecimal pDecimal) Add a decimal to value.voiddivide(OceanusNewDecimal pDivisor) Divide by another decimal.intObtain the fractional part of the decimal.longObtain the integral part of the decimal.voidmultiply(OceanusNewDecimal pMultiplicand) Multiply by another decimalintscale()Obtain the scale of the decimal.intsignum()Obtain the sign of the decimal.voidsubtract(OceanusNewDecimal pDecimal) Subtract a decimal from value.Convert to BigDecimal.toString()
-
Field Details
-
MAX_DECIMALS
public static final int MAX_DECIMALSThe Maximum # of Decimals.- See Also:
-
-
Constructor Details
-
OceanusNewDecimal
public OceanusNewDecimal(int pScale) Constructor.- Parameters:
pScale- the number of decimal digits
-
OceanusNewDecimal
Constructor.- Parameters:
pSource- the source BigDecimal
-
OceanusNewDecimal
public OceanusNewDecimal(long pIntegral, int pFractional, int pSign, int pScale) Constructor.- Parameters:
pIntegral- the integral part of the decimal.pFractional- the fractional part of the decimalpSign- the sign of the decimalpScale- the number of decimal digits
-
-
Method Details
-
integralValue
public long integralValue()Obtain the integral part of the decimal.- Returns:
- the integral part of the decimal
-
signum
public int signum()Obtain the sign of the decimal.- Returns:
- -1, 0, or 1 as the value of this Decimal is negative, zero, or positive
-
fractionalValue
public int fractionalValue()Obtain the fractional part of the decimal.- Returns:
- the fractional part of the decimal
-
scale
public int scale()Obtain the scale of the decimal.- Returns:
- the scale of the decimal
-
add
Add a decimal to value.- Parameters:
pDecimal- the decimal to add to this value
-
subtract
Subtract a decimal from value.- Parameters:
pDecimal- the decimal to subtract from this value
-
multiply
Multiply by another decimalThis function splits the values into three separate integers and then performs long arithmetic to prevent loss of precision. The value is represented as (x,y,z,s) where the decimal may be written as x*232 + y + z*10-s and x,y,z,s are all integers.
The product of (x1, y1, z1, s) by (x2, y2, z2, t) is therefore x1*x2*264 (discardable) + (x1*y2 + x2*y1)*232 + x2*y2 + x1*z2*232*10-t + x2*z1*232*10-s + y1*z2*10-t + y2*z1*10-s + z1*z2*10-s-t
- Parameters:
pMultiplicand- the decimal to multiply by
-
divide
Divide by another decimal.This function uses BigDecimal to perform the calculation
- Parameters:
pDivisor- the decimal to divide by
-
toBigDecimal
Convert to BigDecimal.- Returns:
- the BigDecimal equivalent
-
toString
-