public class IntNum extends RatNum implements java.io.Externalizable
Modifier and Type | Field and Description |
---|---|
int |
ival
All integers are stored in 2's-complement form.
|
int[] |
words |
Constructor and Description |
---|
IntNum() |
IntNum(int value)
Create a new (non-shared) IntNum, and initialize to an int.
|
Modifier and Type | Method and Description |
---|---|
static IntNum |
abs(IntNum x) |
static IntNum |
add(int x,
int y)
Add two ints, yielding an IntNum.
|
static IntNum |
add(IntNum x,
int y)
Add an IntNum and an int, yielding a new IntNum.
|
static IntNum |
add(IntNum x,
IntNum y)
Add two IntNums, yielding their sum as another IntNum.
|
static IntNum |
add(IntNum x,
IntNum y,
int k)
Add two IntNums, yielding their sum as another IntNum.
|
Numeric |
add(java.lang.Object y,
int k)
Return this + k * obj.
|
static IntNum |
alloc(int nwords)
Allocate a new non-shared IntNum.
|
java.math.BigDecimal |
asBigDecimal() |
java.math.BigInteger |
asBigInteger() |
static IntNum |
asIntNumOrNull(java.lang.Object value) |
IntNum |
canonicalize() |
static int |
compare(IntNum x,
IntNum y)
Return -1, 0, or 1, depending on which value is greater.
|
static int |
compare(IntNum x,
long y)
Return -1, 0, or 1, depending on which value is greater.
|
int |
compare(java.lang.Object obj)
Return an integer for which of
this or obj is larger. |
IntNum |
denominator() |
Numeric |
div(java.lang.Object y) |
static void |
divide(IntNum x,
IntNum y,
IntNum quotient,
IntNum remainder,
int rounding_mode)
Divide two integers, yielding quotient and remainder.
|
static void |
divide(long x,
long y,
IntNum quotient,
IntNum remainder,
int rounding_mode) |
double |
doubleValue()
The value of the real component, as a double.
|
static boolean |
equals(IntNum x,
IntNum y) |
boolean |
equals(java.lang.Object obj) |
void |
format(int radix,
java.lang.StringBuffer buffer) |
void |
format(int radix,
java.lang.StringBuilder buffer) |
static int |
gcd(int a,
int b)
Calculate Greatest Common Divisor for non-negative ints.
|
static IntNum |
gcd(IntNum x,
IntNum y) |
void |
getAbsolute(int[] words)
Copy the abolute value of this into an array of words.
|
int |
hashCode() |
boolean |
inIntRange()
Does this value fit in a signed 32-bit
int ? |
boolean |
inLongRange()
Does this value fit in a signed 64-bit
long ? |
boolean |
inRange(long lo,
long hi)
Is this integer both
>= lo and <= hi ?. |
int |
intLength()
Calculates
ceiling(log2(this < 0 ? -this : this+1)) . |
int |
intValue() |
static int |
intValue(java.lang.Object obj)
Cast an Object to an int.
|
boolean |
isMinusOne() |
boolean |
isNegative() |
boolean |
isOdd() |
boolean |
isOne() |
boolean |
isZero() |
static IntNum |
lcm(IntNum x,
IntNum y) |
long |
longValue() |
static IntNum |
make(int value)
Return a (possibly-shared) IntNum with a given int value.
|
static IntNum |
make(int[] words) |
static IntNum |
make(int[] words,
int len)
Make a canonicalized IntNum from an array of words.
|
static IntNum |
make(long value) |
static IntNum |
minusOne()
Return the IntNum for -1.
|
static IntNum |
modulo(IntNum x,
IntNum y) |
Numeric |
mul(java.lang.Object y) |
Numeric |
neg() |
static IntNum |
neg(IntNum x) |
static boolean |
negate(int[] dest,
int[] src,
int len)
Set dest[0:len-1] to the negation of src[0:len-1].
|
IntNum |
numerator() |
static IntNum |
one() |
Numeric |
power(IntNum y)
Return this raised to an integer power.
|
static IntNum |
power(IntNum x,
int y)
Calculate the integral power of an IntNum.
|
static IntNum |
quotient(IntNum x,
IntNum y) |
static IntNum |
quotient(IntNum x,
IntNum y,
int rounding_mode) |
void |
readExternal(java.io.ObjectInput in) |
java.lang.Object |
readResolve() |
void |
realloc(int nwords)
Change words.length to nwords.
|
static IntNum |
remainder(IntNum x,
IntNum y) |
static IntNum |
remainder(IntNum x,
IntNum y,
int rounding_mode) |
double |
roundToDouble(int exp,
boolean neg,
boolean remainder)
Convert a semi-processed IntNum to double.
|
void |
set(int y)
Destructively set the value of this to an int.
|
void |
set(int[] words,
int length)
Destructively set the value of this to the given words.
|
void |
set(IntNum y)
Destructively set the value of this to that of y.
|
void |
set(long y)
Destructively set the value of this to a long.
|
void |
setAdd(int y)
Destructively add an int to this.
|
void |
setAdd(IntNum x,
int y)
Set this to the sum of x and y.
|
void |
setNegative()
Destructively negate this.
|
void |
setNegative(IntNum x)
Destructively set this to the negative of x.
|
static IntNum |
shift(IntNum x,
int count) |
int |
sign()
Return 1 if
>0 ; 0 if ==0 ; -1 if <0 ; -2 if NaN . |
static IntNum |
sub(IntNum x,
IntNum y)
Subtract two IntNums, yielding their sum as another IntNum.
|
static IntNum |
ten() |
static IntNum |
times(int x,
int y)
Multiply two ints, yielding an IntNum.
|
static IntNum |
times(IntNum x,
int y) |
static IntNum |
times(IntNum x,
IntNum y) |
IntNum |
toExactInt(int rounding_mode)
Converts to an exact integer, with specified rounding mode.
|
RealNum |
toInt(int rounding_mode)
Converts a real to an integer, according to a specified rounding mode.
|
java.lang.String |
toString(int radix) |
static IntNum |
valueOf(byte[] digits,
int byte_len,
boolean negative,
int radix) |
static IntNum |
valueOf(char[] buf,
int offset,
int length,
int radix,
boolean negative) |
static IntNum |
valueOf(int value)
Return a (possibly-shared) IntNum with a given int value.
|
static IntNum |
valueOf(long value)
Return a (possibly-shared) IntNum with a given long value.
|
static IntNum |
valueOf(java.lang.String s) |
static IntNum |
valueOf(java.lang.String s,
int radix) |
static IntNum |
valueOfUnsigned(int value)
Make an IntNum from an unsigned 32-bit value.
|
static IntNum |
valueOfUnsigned(long value)
Make an IntNum from an unsigned 64-bit value.
|
static int |
wordsNeeded(int[] words,
int len)
Calculate how many words are significant in words[0:len-1].
|
void |
writeExternal(java.io.ObjectOutput out) |
static IntNum |
zero() |
add, asRatNumOrNull, classifyFinite, compare, divide, equals, infinity, isExact, make, neg, rationalize, rneg, times, toExact, valueOf
abs, add, angle, asRealNumOrNull, compareTo, conjugate, cos, divide, exp, im, isReal, log, max, min, re, sin, sqrt, tan, times, toExactInt, toExactInt, toInexact, toInt, toScaledInt, toScaledInt, toScaledInt, toStringDecimal, toStringScientific, toStringScientific, toStringScientific, toStringScientific, unitQuaternion, unitVector, vectorPart
add, addReversed, colatitude, compare, complexPart, divide, divReversed, equals, imMinusOne, imOne, jm, km, longitude, make, make, mulReversed, neg, polar, polar, power, times
add, compare, divide, doubleImagValue, doubleJmagValue, doubleKmagValue, doubleRealValue, equals, jmMinusOne, jmOne, kmMinusOne, kmOne, make, make, neg, number, polar, polar, power, times
add, compare, compareReversed, dimensions, divide, imValue, jmValue, kmValue, make, make, make, reValue, times, unit
add, asNumericOrNull, div_inv, floatValue, geq, grt, mul_ident, sub, toString
public int ival
public int[] words
public IntNum()
public IntNum(int value)
value
- the initial valuepublic static final IntNum zero()
public static final IntNum one()
public static final IntNum ten()
public static IntNum minusOne()
public static IntNum asIntNumOrNull(java.lang.Object value)
public static IntNum alloc(int nwords)
nwords
- number of words to allocatepublic void realloc(int nwords)
public final IntNum denominator()
denominator
in class RatNum
public final boolean isNegative()
isNegative
in class RealNum
public int sign()
RealNum
>0
; 0 if ==0
; -1 if <0
; -2 if NaN
.public static int compare(IntNum x, IntNum y)
public static int compare(IntNum x, long y)
public int compare(java.lang.Object obj)
Numeric
this
or obj
is larger.
Return 1 if this>obj
; 0 if this==obj
;
-1 if this<obj
;
-2 if this!=obj
otherwise (for example if either is NaN);
-3 if not comparable (incompatible types).public final boolean isOdd()
public final boolean isOne()
public final boolean isMinusOne()
public static int wordsNeeded(int[] words, int len)
x
such that
x>0 && words[0:x-1]==words[0:len-1]
,
when words
is viewed as a 2's complement integer.public IntNum canonicalize()
public static final IntNum add(int x, int y)
public void setAdd(IntNum x, int y)
public final void setAdd(int y)
public final void set(int y)
public final void set(long y)
public final void set(int[] words, int length)
public final void set(IntNum y)
public static IntNum add(IntNum x, IntNum y)
public static IntNum sub(IntNum x, IntNum y)
public static IntNum add(IntNum x, IntNum y, int k)
public static final IntNum times(int x, int y)
public static void divide(long x, long y, IntNum quotient, IntNum remainder, int rounding_mode)
public static void divide(IntNum x, IntNum y, IntNum quotient, IntNum remainder, int rounding_mode)
x
- the numerator in the divisiony
- the denominator in the divisionquotient
- is set to the quotient of the result (iff quotient!=null)remainder
- is set to the remainder of the result
(iff remainder!=null)rounding_mode
- one of FLOOR, CEILING, TRUNCATE, or ROUND.public IntNum toExactInt(int rounding_mode)
RealNum
toExactInt
in class RatNum
public RealNum toInt(int rounding_mode)
RealNum
public Numeric power(IntNum y)
Numeric
y < 0
, returns div_inv of the result.public static IntNum power(IntNum x, int y)
x
- the value (base) to exponentiatey
- the exponent (must be non-negative)public static final int gcd(int a, int b)
public void format(int radix, java.lang.StringBuffer buffer)
public void format(int radix, java.lang.StringBuilder buffer)
public static int intValue(java.lang.Object obj)
public long longValue()
longValue
in class Quaternion
public int hashCode()
hashCode
in class java.lang.Object
public static IntNum make(int value)
public static IntNum valueOfUnsigned(long value)
public static IntNum valueOfUnsigned(int value)
public static IntNum make(int[] words, int len)
public static IntNum make(int[] words)
public static IntNum make(long value)
public static IntNum valueOf(int value)
public static IntNum valueOf(long value)
public static IntNum valueOf(char[] buf, int offset, int length, int radix, boolean negative)
public static IntNum valueOf(java.lang.String s, int radix) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public static IntNum valueOf(byte[] digits, int byte_len, boolean negative, int radix)
public static IntNum valueOf(java.lang.String s) throws java.lang.NumberFormatException
java.lang.NumberFormatException
public double doubleValue()
Quantity
doubleValue
in class Quaternion
public double roundToDouble(int exp, boolean neg, boolean remainder)
exp
- power of two, positive or negative, by which to multiplyneg
- true if negativeremainder
- true if the IntNum is the result of a truncating
division that had non-zero remainder. To ensure proper rounding in
this case, the IntNum must have at least 54 bits.public Numeric add(java.lang.Object y, int k)
Numeric
public void getAbsolute(int[] words)
words.length >= (this.words == null ? 1 : this.ival)
.
Result is zero-extended, but need not be a valid 2's complement number.public static boolean negate(int[] dest, int[] src, int len)
public void setNegative(IntNum x)
public final void setNegative()
public int intLength()
ceiling(log2(this < 0 ? -this : this+1))
.
See Common Lisp: the Language, 2nd ed, p. 361.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
java.lang.ClassNotFoundException
public java.lang.Object readResolve() throws java.io.ObjectStreamException
java.io.ObjectStreamException
public java.math.BigInteger asBigInteger()
public java.math.BigDecimal asBigDecimal()
asBigDecimal
in class RealNum
public boolean inRange(long lo, long hi)
>= lo
and <= hi
?.public boolean inIntRange()
int
?public boolean inLongRange()
long
?