public final class Int128 extends java.lang.Number implements java.lang.Comparable<Int128>
Modifier and Type | Field and Description |
---|---|
static int |
BYTES
Size of this numeric type in bytes.
|
static Int128 |
EIGHT |
static Int128 |
FIVE |
static Int128 |
FOUR |
static Int128 |
MAX_VALUE
A constant holding the maximum value an
Int128 can
have, 2127-1. |
static Int128 |
MIN_VALUE
A constant holding the minimum value an
Int128 can
have, -2127. |
static Int128 |
MINUS_ONE |
static Int128 |
NINE |
static Int128 |
ONE |
static Int128 |
SEVEN |
static Int128 |
SIX |
static int |
SIZE
Size of this numeric type in bits.
|
static Int128 |
TEN |
static Int128 |
THREE |
static Int128 |
TWO |
static Int128 |
ZERO |
Modifier and Type | Method and Description |
---|---|
Int128 |
abs()
Return the absolute value of
this . |
Int128 |
add(Int128 other)
Add
other to this , returning the result. |
Int128 |
and(Int128 other)
Calculates the bitwise and of
this with other
(this & other ). |
int |
compareTo(Int128 n) |
int |
compareToUnsigned(Int128 n)
Compares
this and n numerically treating the values
as unsigned. |
Int128 |
decrement()
Decrement a number.
|
Int128 |
div2()
Similar to
shiftRight() , but rounds towards zero. |
Int128 |
divide(Int128 divisor)
Divide
this by the specified divisor. |
double |
doubleValue() |
boolean |
equals(java.lang.Object obj) |
float |
floatValue() |
static Int128 |
from(byte[] bytes)
Factory method for materialising an
Int128 from an array
of bytes. |
static Int128 |
from(byte[] bytes,
int offset)
Factory method for materialising an
Int128 from an array
of bytes. |
static Int128 |
from(int value)
Factory method for materialising an
Int128 from an int value. |
static Int128 |
from(long value)
Factory method for materialising an
Int128 from a long value. |
static Int128 |
from(long high,
long low)
Factory method for materialising an
Int128 from two long
values. |
static Int128 |
from(short value)
Factory method for materialising an
Int128 from a short
value. |
static Int128 |
from(java.lang.String s)
Factory method for materialising an
Int128 from a string. |
long |
getHigh()
Return the most significant word.
|
long |
getLow()
Return the least significant word.
|
int |
hashCode() |
Int128 |
increment()
Increment a number.
|
int |
intValue() |
Int128 |
invert()
Return the value of
~this . |
boolean |
isEven()
Return
true if this is an even number. |
boolean |
isNegative()
Return
true if the Int128 is negative. |
boolean |
isOdd()
Return
true if this is an odd number. |
boolean |
isZero()
Return
true if this is zero. |
Int128 |
logicalShiftRight()
Logical shift
this right 1 bit. |
long |
longValue() |
Int128 |
multiply(Int128 multiplicand)
Multiply
this by the specified multiplicand. |
Int128 |
negate()
Return the value of
0 - this . |
int |
numberOfLeadingZeros()
Returns the number of zero bits preceding the highest-order
("leftmost") one-bit in the two's complement binary representation
of the specified
long value. |
Int128 |
or(Int128 other)
Calculates the bitwise inclusive-or of
this with other
(this | other ). |
Int128 |
remainder(Int128 divisor)
Return the remainder of the division of
this by
the specified divisor. |
Int128 |
shiftLeft()
Shift
this left 1 bit. |
Int128 |
shiftRight()
Arithmetic shift
this right 1 bit. |
Int128 |
subtract(Int128 other)
Subtract
other from this , returning the result. |
byte[] |
toByteArray()
Convert value to an array of bytes.
|
byte[] |
toByteArray(byte[] bytes,
int offset)
Convert value to an array of bytes.
|
java.lang.String |
toString() |
Int128 |
xor(Int128 other)
Calculates the exclusive-or of
this with other
(this ^ other ). |
public static final int SIZE
public static final int BYTES
public static final Int128 MIN_VALUE
Int128
can
have, -2127.public static final Int128 MAX_VALUE
Int128
can
have, 2127-1.public static final Int128 ZERO
public static final Int128 ONE
public static final Int128 TWO
public static final Int128 THREE
public static final Int128 FOUR
public static final Int128 FIVE
public static final Int128 SIX
public static final Int128 SEVEN
public static final Int128 EIGHT
public static final Int128 NINE
public static final Int128 TEN
public static final Int128 MINUS_ONE
public static Int128 from(short value)
Int128
from a short
value.public static Int128 from(int value)
Int128
from an int
value.public static Int128 from(long value)
Int128
from a long
value.
Note that values are sign extended into the 128 bit value.public static Int128 from(long high, long low)
Int128
from two long
values. high
is the most significant word, and low
the least
significant.high
- The most significant word of the 128 bit value.low
- The least significant word of the 128 bit value.(high << 64) | low
as an Int128
type.public static Int128 from(byte[] bytes)
Int128
from an array
of bytes. The array is most-significant byte first, and must not be
zero length.
If the array is smaller than BYTES
, then it is effectively
padded with leading bytes with the correct sign.
If the array is longer than BYTES
, then values at index
BYTES
and beyond are ignored.
bytes
- The array of bytes to be used.bytes
as an Int128
type.java.lang.IllegalArgumentException
- if bytes
is 0 length.toByteArray()
public static Int128 from(byte[] bytes, int offset)
Int128
from an array
of bytes. The array is most-significant byte first.bytes
- The array of bytes to be used.offset
- The offset within the array to be used.bytes
from offset
as an Int128
type.toByteArray()
public static Int128 from(java.lang.String s)
Int128
from a string.
Conversion is performed base 10 and leading sign characters are
permitted.s
- The array of bytes to be used.s
as an Int128
type.java.lang.NumberFormatException
- if s
is not a valid
integer number.public byte[] toByteArray()
BYTES
bytes long, and
will be zero filled to suit the actual value.public byte[] toByteArray(byte[] bytes, int offset)
offset
.
The array must be at least offset + BYTES
long.bytes
- The array to place the bytes in.offset
- The offset within the array to place the bytes.bytes
.public Int128 add(Int128 other)
other
to this
, returning the result.other
- The addend.Int128
with the value this + other
.public Int128 subtract(Int128 other)
other
from this
, returning the result.other
- The subtrahend.Int128
with the value this - other
.public Int128 multiply(Int128 multiplicand)
this
by the specified multiplicand.multiplicand
- The multiplicand to multiply this
by.this * multiplicand
.public Int128 increment()
this.add(Int128.ONE)
, but
faster.public Int128 decrement()
this.subtract(Int128.ONE)
, but
faster.public Int128 divide(Int128 divisor)
this
by the specified divisor.divisor
- The divisor to divide this
by.floor(this / divisor)
.public Int128 remainder(Int128 divisor)
this
by
the specified divisor.divisor
- The divisor to divide this
by.this / divisor
.public Int128 shiftLeft()
this
left 1 bit. A zero bit is moved into the
leftmost bit.this
left one bit.public Int128 shiftRight()
this
right 1 bit. The current value
of the sign bit is duplicated into the rightmost bit.this
right one bit.public Int128 logicalShiftRight()
this
right 1 bit. Zeros are shifted into
the rightmost bit.this
right one bit.public Int128 div2()
shiftRight()
, but rounds towards zero.this / 2
.public Int128 abs()
this
.
Note that, similarly to other two's complement numbers, the absolute value of the maximal negative value is returned as itself.
this
.public Int128 negate()
0 - this
.
Note that, similarly to other two's complement numbers, the negative value of the maximal negative value is returned as itself.
this
.public Int128 invert()
~this
.this
.public int compareTo(Int128 n)
compareTo
in interface java.lang.Comparable<Int128>
public int compareToUnsigned(Int128 n)
this
and n
numerically treating the values
as unsigned.n
- the second Int128
to compare.0
if this == n
; a value less
than 0
if this < n
as unsigned values; and
a value greater than 0
if this > n
as
unsigned valuespublic long getHigh()
public long getLow()
public int intValue()
intValue
in class java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public double doubleValue()
doubleValue
in class java.lang.Number
public Int128 or(Int128 other)
this
with other
(this | other
).other
- The value to inclusive-or with this
.this | other
public Int128 and(Int128 other)
this
with other
(this & other
).other
- The value to and with this
.this & other
public Int128 xor(Int128 other)
this
with other
(this ^ other
).other
- The value to exclusive-or with this
.this ^ other
public int numberOfLeadingZeros()
long
value. Returns 128 if the
specified value has no one-bits in its two's complement representation,
in other words if it is equal to zero.
Note that this method is closely related to the logarithm base 2.
For all positive long
values x:
127 - numberOfLeadingZeros(x)
128 - numberOfLeadingZeros(x - 1)
long
value, or 128 if the value
is equal to zero.public boolean isNegative()
true
if the Int128
is negative.true
if the Int128
is negative.public boolean isZero()
true
if this
is zero.true
if this
is zero.public boolean isEven()
true
if this
is an even number.true
if this
is an even number.public boolean isOdd()
true
if this
is an odd number.true
if this
is an odd number.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object