Package net.sourceforge.uiq3.math
Class BCDInteger
- java.lang.Object
-
- net.sourceforge.uiq3.math.BCDInteger
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]Digitsnumber: sum(i = 0 ...private static StringINTEGER_VALUES_CAN_NOT_USE_LOGARITHMIC_FUNCTIONSprivate static StringINTEGER_VALUES_CAN_NOT_USE_TRIGONOMETRIC_FUNCTIONSprivate @Nullable BCDIntegerLast_Remainderremainder of last long divisionprivate byteLast_Remainder_Shortremainder of last short divisionprivate static LoggerLoggerClass logger instance.private booleanNegativesignprivate static byte[]Null_DigitsNo digitsstatic BCDIntegerNum_00static BCDIntegerNum_11static BCDIntegerNum_1010static BCDIntegerNum_22private intNum_Digitsnumber of digitsprivate static StringTAGClass logger tag.-
Fields inherited from interface net.sourceforge.uiq3.math.Number
Compare_Equal, Compare_Greater, Compare_Less, Effective_Precision, Max_Precision
-
-
Constructor Summary
Constructors Constructor Description BCDInteger()new Number, val = 0, length = 0BCDInteger(byte @NotNull [] Digits, boolean Negative)new Number from attributes.BCDInteger(int n)new Number, val = 0, length = nBCDInteger(long value)new Number, val = 0, length = nBCDInteger(@NotNull CharSequence s)new Number, val and length from stringBCDInteger(@NotNull BCDInteger Value)new Number from existing number
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull Number$div(@NotNull Number y)signed division@NotNull Number$minus(@NotNull Number y)signed subtraction@NotNull Number$plus(@NotNull Number y)signed addition@NotNull Number$times(@NotNull Number y)signed multiplication@NotNull Number$times$times(@NotNull Number y)xy@NotNull Numberabs()|x|(package private) @NotNull BCDIntegeraddUnsigned(int y)unsigned (absolute) addition of one digitprivate @NotNull BCDIntegeraddUnsigned(@NotNull BCDInteger a)unsigned (absolute) addition@NotNull Numberand(@NotNull Number y)Logical and@NotNull Numberarc_cos()arc cosine@NotNull Numberarc_cos(@NotNull Number Half_Circle)arc cosine@NotNull Numberarc_cos_hyp()area hyperbolic cosine: loge (x + √(x-1) × √(x+1))@NotNull Numberarc_sin()arc sine@NotNull Numberarc_sin(@NotNull Number Half_Circle)arc sine@NotNull Numberarc_sin_hyp()area hyperbolic sine: loge (x + √(x² + 1))@NotNull Numberarc_tan()arc tangent@NotNull Numberarc_tan(@NotNull Number Half_Circle)arc tangent@NotNull Numberarc_tan_hyp()area hyperbolic tangent: loge ((1 + x) ÷ (1 - x)) / 2@NotNull BCDFloatAs_BCDFloat()Either convert to a BCDFloat or return this.@NotNull BCDFractionAs_BCDFraction()Either convert to a or return this.@NotNull BCDIntegerAs_BCDInteger()Either convert to a BCDInteger or return this.@NotNull Objectclone()clone the float - but it might be easier to use the provided copy Constructor instead.@NotNull NumberClone()clone the integer - but it might be easier to use the provided copy Constructor instead.longCoefficient_As_Long()coefficient - while a 18 digits number can also be represented as an long an 18digits multiplication need a 36digits temporary and that is more then a long can do.intCompare(@NotNull Number Value)signed compare(package private) intCompare_Unsigned(@NotNull BCDInteger Value)unsigned (absolute) compareintcompareTo(@NotNull Number rightValue)@NotNull Numbercos()cos (x)@NotNull Numbercos(@NotNull Number Half_Circle)cosine@NotNull Numbercos_hyp()Hyperbolic cosine: (Exponent^x + Exponent^-x)/2byte[]Digits()number: sum(i = 0 ...private @NotNull BCDIntegerdivUnsigned(int y)predicate: Num_Digits > v.numDigits, v = v.Normalize(), v.numDigits > 1private @NotNull BCDIntegerdivUnsigned(@NotNull BCDInteger Right)predicate: Num_Digits > v.numDigits, v = v.Normalize(), v.numDigits > 1booleanequals(@NotNull Object rightValue)@NotNull Numberexp_10()10x@NotNull Numberexp_e()exintExponent()current exponent - note that the exponent is based on the internal representation where the radix point is right most.@NotNull NumberFix(int Decimal, int Exponent)Round to a given Precision after the decimal point.@NotNull NumberFrac()Recompose a frac double from the given data.@NotNull BCDIntegergcd(@NotNull BCDInteger y)<>calculate the greatest common denominator using the Euclidean algorithm>inthashCode()intIndirect_Value(int Digit_Count)Get valuef or indirect addressing.@NotNull NumberInteger()integer part of the BCDFloatbooleanIs_Finite()current value is a normal numberbooleanIs_Infinite()current value is Infinity.booleanIs_Integer()Current value is integer value.booleanIs_NaN()current value is not a numberbooleanIs_Negative()Current value us negativebooleanIs_Zero()value is 0(package private) @Nullable BCDIntegerLast_Remainder()@NotNull Numberlog_10()log10 (x)@NotNull Numberlog_e()loge (x)private @NotNull BCDIntegermid(int start, int len)get part of numberprivate @NotNull BCDIntegermulUnsigned(int y)unsigned (absolute) multiplication by one digitprivate @NotNull BCDIntegermulUnsigned(@NotNull BCDInteger y)unsigned (absolute) multiplication@NotNull Numberneg()voidNormalize()Normalize (remove leading zero digits)@NotNull Numbernot()Logical notintNum_Digits()returns number of digits@NotNull Numberor(@NotNull Number y)Logical or@NotNull NumberP_To_X(@NotNull Number θ)Convert Polar to Rectangle Coordinates@NotNull NumberP_To_X(Number θ, Number Half_Circle)Convert Polar to Rectangle Coordinates@NotNull NumberP_To_Y(@NotNull Number θ)Convert Polar to Rectangle Coordinates@NotNull NumberP_To_Y(@NotNull Number θ, @NotNull Number Half_Circle)Convert Polar to Rectangle Coordinates@NotNull NumberR_To_R(@NotNull Number y)Convert Rectangle to Polar Coordinates@NotNull NumberR_To_θ(@NotNull Number y)Convert Rectangle to Polar Coordinates@NotNull NumberR_To_θ(@NotNull Number y, @NotNull Number Half_Circle)Convert Rectangle to Polar Coordinates@NotNull Numberroot(@NotNull Number r)r√x@NotNull NumberRound()Round to effective Precision and Exponent.@NotNull NumberRound(int Precision, int Exponent)Round to a given Precision and Exponent.(package private) @NotNull BCDIntegerShift_Left(int n)shift left by n digits (= divide by 10n)(package private) @NotNull BCDIntegerShift_Right(int n)shift right by n digits (= multiply by 10n)@NotNull Numbersin()sine@NotNull Numbersin(@NotNull Number Half_Circle)sine@NotNull Numbersin_hyp()hyperbolic sine: (ex - e-x) ÷ 2@NotNull Numbersquare()x²@NotNull Numbersquare_root()²√xprivate @NotNull BCDIntegersubUnsigned(@NotNull BCDInteger y)unsigned (absolute) subtraction@NotNull Numbertan()tan x@NotNull Numbertan(@NotNull Number Half_Circle)tangent@NotNull Numbertan_hyp()Hyperbolic tangent: (e2x - 1) ÷ (e2x + 1)@NotNull StringTo_Debug_String()convert to native/debug string representationintTo_Integer()Convert to integerlongTo_Long()Convert to long integer@NotNull StringtoString()return string representation of number@NotNull Numberxor(@NotNull Number y)Logical xor
-
-
-
Field Detail
-
INTEGER_VALUES_CAN_NOT_USE_LOGARITHMIC_FUNCTIONS
private static final String INTEGER_VALUES_CAN_NOT_USE_LOGARITHMIC_FUNCTIONS
- See Also:
- Constant Field Values
-
INTEGER_VALUES_CAN_NOT_USE_TRIGONOMETRIC_FUNCTIONS
private static final String INTEGER_VALUES_CAN_NOT_USE_TRIGONOMETRIC_FUNCTIONS
- See Also:
- Constant Field Values
-
Logger
private static final Logger Logger
Class logger instance.
-
Null_Digits
private static final byte[] Null_Digits
No digits
-
TAG
private static final String TAG
Class logger tag.
-
Num_0
public static final BCDInteger Num_0
0
-
Num_1
public static final BCDInteger Num_1
1
-
Num_10
public static final BCDInteger Num_10
10
-
Num_2
public static final BCDInteger Num_2
2
-
Digits
private byte[] Digits
number: sum(i = 0 ... Num_Digits-1; Digits[i]*10^i)
-
Last_Remainder
@Nullable private @Nullable BCDInteger Last_Remainder
remainder of last long division
-
Last_Remainder_Short
private byte Last_Remainder_Short
remainder of last short division
-
Negative
private boolean Negative
sign
-
Num_Digits
private int Num_Digits
number of digits
-
-
Constructor Detail
-
BCDInteger
public BCDInteger()
new Number, val = 0, length = 0
-
BCDInteger
public BCDInteger(@NotNull @NotNull BCDInteger Value)new Number from existing number- Parameters:
Value- value to copy
-
BCDInteger
public BCDInteger(byte @NotNull [] Digits, boolean Negative)new Number from attributes.
-
BCDInteger
public BCDInteger(@NotNull @NotNull CharSequence s)new Number, val and length from string- Parameters:
s- string to extract number from
-
BCDInteger
public BCDInteger(int n)
new Number, val = 0, length = n- Parameters:
n- digits for new number
-
BCDInteger
public BCDInteger(long value)
new Number, val = 0, length = n- Parameters:
value- to init the integer from
-
-
Method Detail
-
$div
@Contract(pure=true) @NotNull public @NotNull Number $div(@NotNull @NotNull Number y)
signed division
-
$minus
@Contract(pure=true) @NotNull public @NotNull Number $minus(@NotNull @NotNull Number y)
signed subtraction
-
$plus
@Contract(pure=true) @NotNull public @NotNull Number $plus(@NotNull @NotNull Number y)
signed addition
-
$times
@Contract(pure=true) @NotNull public @NotNull Number $times(@NotNull @NotNull Number y)
signed multiplication
-
$times$times
@Contract(pure=true) @NotNull public @NotNull Number $times$times(@NotNull @NotNull Number y) throws BCDError
xy- Specified by:
$times$timesin interfaceNumber- Parameters:
y- right value- Returns:
- xy
- Throws:
BCDError- calculation error
-
As_BCDFloat
@NotNull public @NotNull BCDFloat As_BCDFloat()
Either convert to a BCDFloat or return this.
- Specified by:
As_BCDFloatin interfaceNumber- Returns:
- value as java int
-
As_BCDFraction
@NotNull public @NotNull BCDFraction As_BCDFraction()
Either convert to a or return this.
- Specified by:
As_BCDFractionin interfaceNumber- Returns:
- value as java int
-
As_BCDInteger
@NotNull public @NotNull BCDInteger As_BCDInteger()
Either convert to a BCDInteger or return this.
- Specified by:
As_BCDIntegerin interfaceNumber- Returns:
- value as java int
-
Clone
@NotNull public @NotNull Number Clone()
clone the integer - but it might be easier to use the provided copy Constructor instead.- Specified by:
Clonein interfaceNumber- Returns:
- a new BCDFloat from an existing one.
- See Also:
Object.clone()
-
Coefficient_As_Long
public long Coefficient_As_Long() throws BCDErrorcoefficient - while a 18 digits number can also be represented as an long an 18digits multiplication need a 36digits temporary and that is more then a long can do.
- Specified by:
Coefficient_As_Longin interfaceNumber- Returns:
- Coefficient
- Throws:
BCDError- when it's not a normal number
-
Compare
public int Compare(@NotNull @NotNull Number Value)signed compare
-
Compare_Unsigned
int Compare_Unsigned(@NotNull @NotNull BCDInteger Value)unsigned (absolute) compare- Parameters:
Value- value to compare with- Returns:
- Compare_Equal
- Values are the same
- Compare_Less
- Left value less the right value
- Compare_Greater
- Left value greater the right value
-
Digits
public byte[] Digits()
number: sum(i = 0 ... Num_Digits-1; Digits[i]*10^i)
-
Exponent
public int Exponent() throws BCDErrorcurrent exponent - note that the exponent is based on the internal representation where the radix point is right most. For example π is 314159265358979324×10-17.
-
Fix
@NotNull public @NotNull Number Fix(int Decimal, int Exponent)
Round to a given Precision after the decimal point.
-
Frac
@NotNull public @NotNull Number Frac()
Recompose a frac double from the given data.
-
Indirect_Value
public int Indirect_Value(int Digit_Count)
Get valuef or indirect addressing.
- Specified by:
Indirect_Valuein interfaceNumber- Parameters:
Digit_Count- Should be 1 … 2 depending if value is used to access memory or perform a goto.- Returns:
- int value for indirect addressing.
-
Integer
@NotNull public @NotNull Number Integer()
integer part of the BCDFloat Do not mix up with To_Integer - This version returns another Number!
-
Is_Finite
public boolean Is_Finite()
current value is a normal number
-
Is_Infinite
public boolean Is_Infinite()
current value is Infinity.- Specified by:
Is_Infinitein interfaceNumber- Returns:
- false since all integer are finite
-
Is_Integer
public boolean Is_Integer()
Current value is integer value.- Specified by:
Is_Integerin interfaceNumber- Returns:
- true since all integers are – well – integers
-
Is_NaN
public boolean Is_NaN()
current value is not a number
-
Is_Negative
public boolean Is_Negative()
Current value us negative- Specified by:
Is_Negativein interfaceNumber- Returns:
- true when x <= -0
-
Is_Zero
public final boolean Is_Zero()
value is 0
-
Last_Remainder
@Nullable @Nullable BCDInteger Last_Remainder()
-
Normalize
public void Normalize()
Normalize (remove leading zero digits)
-
Num_Digits
public int Num_Digits()
returns number of digits- Specified by:
Num_Digitsin interfaceNumber- Returns:
- Num_Digits
-
P_To_X
@Contract(pure=true) @NotNull public @NotNull Number P_To_X(@NotNull Number θ, @NotNull Number Half_Circle)
Convert Polar to Rectangle Coordinates
-
P_To_X
@Contract(pure=true) @NotNull public @NotNull Number P_To_X(@NotNull @NotNull Number θ)
Convert Polar to Rectangle Coordinates
-
P_To_Y
@Contract(pure=true) @NotNull public @NotNull Number P_To_Y(@NotNull @NotNull Number θ)
Convert Polar to Rectangle Coordinates
-
P_To_Y
@Contract(pure=true) @NotNull public @NotNull Number P_To_Y(@NotNull @NotNull Number θ, @NotNull @NotNull Number Half_Circle)
Convert Polar to Rectangle Coordinates
-
R_To_R
@Contract(pure=true) @NotNull public @NotNull Number R_To_R(@NotNull @NotNull Number y)
Convert Rectangle to Polar Coordinates
-
R_To_θ
@Contract(pure=true) @NotNull public @NotNull Number R_To_θ(@NotNull @NotNull Number y)
Convert Rectangle to Polar Coordinates
-
R_To_θ
@Contract(pure=true) @NotNull public @NotNull Number R_To_θ(@NotNull @NotNull Number y, @NotNull @NotNull Number Half_Circle)
Convert Rectangle to Polar Coordinates
-
Round
@NotNull public @NotNull Number Round()
Round to effective Precision and Exponent.
-
Round
@NotNull public @NotNull Number Round(int Precision, int Exponent)
Round to a given Precision and Exponent.
-
Shift_Left
@NotNull @NotNull BCDInteger Shift_Left(int n)
shift left by n digits (= divide by 10n)- Parameters:
n- digits to shift- Returns:
- x ÷ 10n
-
Shift_Right
@NotNull @NotNull BCDInteger Shift_Right(int n)
shift right by n digits (= multiply by 10n)- Parameters:
n- digits to shift- Returns:
- x × 10n
-
To_Debug_String
@NotNull public @NotNull String To_Debug_String()
convert to native/debug string representation- Specified by:
To_Debug_Stringin interfaceNumber- Returns:
- (Coefficient, Exponent)
-
To_Integer
public int To_Integer()
Convert to integer
Do not mix up with Integer – This version returns a Java int! Actualy it just returns
(int)To_Long ()- Specified by:
To_Integerin interfaceNumber- Returns:
- value as java int
-
To_Long
public long To_Long()
Description copied from interface:NumberConvert to long integerDo not mix up with Integer - This version returns a Java int!
-
abs
@Contract(pure=true) @NotNull public @NotNull Number abs()
|x|
-
addUnsigned
@NotNull private @NotNull BCDInteger addUnsigned(@NotNull @NotNull BCDInteger a)
unsigned (absolute) addition- Parameters:
a- right value- Returns:
- abs (x) + abs (y)
-
addUnsigned
@NotNull @NotNull BCDInteger addUnsigned(int y)
unsigned (absolute) addition of one digit- Parameters:
y- right value- Returns:
- abs (x) - abs (y)
-
and
@Contract(pure=true) @NotNull public @NotNull Number and(@NotNull @NotNull Number y)
Logical and
-
arc_cos
@Contract(pure=true) @NotNull public @NotNull Number arc_cos()
arc cosine
-
arc_cos
@Contract(pure=true) @NotNull public @NotNull Number arc_cos(@NotNull @NotNull Number Half_Circle)
arc cosine
-
arc_cos_hyp
@Contract(pure=true) @NotNull public @NotNull Number arc_cos_hyp()
area hyperbolic cosine: loge (x + √(x-1) × √(x+1))- Specified by:
arc_cos_hypin interfaceNumber- Returns:
- Hyperbolic sine.
-
arc_sin
@Contract(pure=true) @NotNull public @NotNull Number arc_sin()
arc sine
-
arc_sin
@Contract(pure=true) @NotNull public @NotNull Number arc_sin(@NotNull @NotNull Number Half_Circle)
arc sine
-
arc_sin_hyp
@Contract(pure=true) @NotNull public @NotNull Number arc_sin_hyp()
area hyperbolic sine: loge (x + √(x² + 1))- Specified by:
arc_sin_hypin interfaceNumber- Returns:
- Hyperbolic sine.
-
arc_tan
@Contract(pure=true) @NotNull public @NotNull Number arc_tan()
arc tangent
-
arc_tan
@Contract(pure=true) @NotNull public @NotNull Number arc_tan(@NotNull @NotNull Number Half_Circle)
arc tangent
-
arc_tan_hyp
@Contract(pure=true) @NotNull public @NotNull Number arc_tan_hyp()
area hyperbolic tangent: loge ((1 + x) ÷ (1 - x)) / 2- Specified by:
arc_tan_hypin interfaceNumber- Returns:
- Hyperbolic sine.
-
clone
@NotNull public @NotNull Object clone() throws CloneNotSupportedException
clone the float - but it might be easier to use the provided copy Constructor instead.- Overrides:
clonein classObject- Returns:
- a new BCDInteger from an existing one.
- Throws:
CloneNotSupportedException- See Also:
Object.clone()
-
compareTo
public int compareTo(@NotNull @NotNull Number rightValue)- Specified by:
compareToin interfaceComparable<Number>- Specified by:
compareToin interfaceNumber- Parameters:
rightValue- value to compare with- Returns:
- Compare_Equal
- Values are the same
- Compare_Less
- Left value less the right value
- Compare_Greater
- Left value greater the right value
- See Also:
Comparable.compareTo(java.lang.Object)
-
cos
@Contract(pure=true) @NotNull public @NotNull Number cos()
cos (x)
-
cos
@Contract(pure=true) @NotNull public @NotNull Number cos(@NotNull @NotNull Number Half_Circle)
cosine
-
cos_hyp
@Contract(pure=true) @NotNull public @NotNull Number cos_hyp()
Hyperbolic cosine: (Exponent^x + Exponent^-x)/2
-
divUnsigned
@NotNull private @NotNull BCDInteger divUnsigned(@NotNull @NotNull BCDInteger Right)
predicate: Num_Digits > v.numDigits, v = v.Normalize(), v.numDigits > 1- Parameters:
Right- right value- Returns:
- abs(x) ÷ abs(y)
-
divUnsigned
@NotNull private @NotNull BCDInteger divUnsigned(int y)
predicate: Num_Digits > v.numDigits, v = v.Normalize(), v.numDigits > 1- Parameters:
y- right value- Returns:
- abs(x) ÷ abs(y)
-
equals
public boolean equals(@NotNull @NotNull Object rightValue)
-
exp_e
@Contract(pure=true) @NotNull public @NotNull Number exp_e()
ex
-
gcd
@NotNull public @NotNull BCDInteger gcd(@NotNull @NotNull BCDInteger y)
<>calculate the greatest common denominator using the Euclidean algorithm>- Parameters:
y- second value- Returns:
- gcd
-
log_10
@Contract(pure=true) @NotNull public @NotNull Number log_10()
log10 (x)
-
log_e
@Contract(pure=true) @NotNull public @NotNull Number log_e()
loge (x)
-
mid
@NotNull private @NotNull BCDInteger mid(int start, int len)
get part of number- Parameters:
start- extract fromlen- extract length- Returns:
- digits from start to start + len
-
mulUnsigned
@NotNull private @NotNull BCDInteger mulUnsigned(@NotNull @NotNull BCDInteger y)
unsigned (absolute) multiplication- Parameters:
y- right value- Returns:
- abs (x) × abs (y)
-
mulUnsigned
@NotNull private @NotNull BCDInteger mulUnsigned(int y)
unsigned (absolute) multiplication by one digit- Parameters:
y- right value- Returns:
- abs (x) × abs (y)
-
neg
@Contract(pure=true) @NotNull public @NotNull Number neg()
-
not
@Contract(pure=true) @NotNull public @NotNull Number not()
Logical not
-
sin
@Contract(pure=true) @NotNull public @NotNull Number sin()
sine
-
sin
@Contract(pure=true) @NotNull public @NotNull Number sin(@NotNull @NotNull Number Half_Circle)
sine
-
sin_hyp
@Contract(pure=true) @NotNull public @NotNull Number sin_hyp()
hyperbolic sine: (ex - e-x) ÷ 2
-
square
@Contract(pure=true) @NotNull public @NotNull Number square()
x²
-
square_root
@Contract(pure=true) @NotNull public @NotNull Number square_root()
²√x- Specified by:
square_rootin interfaceNumber- Returns:
- ²√x
-
subUnsigned
@NotNull private @NotNull BCDInteger subUnsigned(@NotNull @NotNull BCDInteger y)
unsigned (absolute) subtraction
predicate: this > a (or this < a if Num_Digits == a.numDigits and underflow in most significant digit is allowed)- Parameters:
y- right value- Returns:
- abs (x) - abs (y)
-
tan
@Contract(pure=true) @NotNull public @NotNull Number tan()
tan x
-
tan
@Contract(pure=true) @NotNull public @NotNull Number tan(@NotNull @NotNull Number Half_Circle)
tangent
-
tan_hyp
@NotNull public @NotNull Number tan_hyp()
Hyperbolic tangent: (e2x - 1) ÷ (e2x + 1)
-
toString
@NotNull public @NotNull String toString()
return string representation of number- Specified by:
toStringin interfaceNumber- Overrides:
toStringin classObject- Returns:
- string representation
- See Also:
Object.toString()
-
-