|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--MyBigInteger
A mutable, arbitrary-precision integer. An arithmetic operation on a
MyBigInteger
never results in overflow or "wrap
around"---instead, the sequence of digits expands as necessary to
accomodate any increase in the stored value's magnitude. For example,
MyBigInteger i = new MyBigInteger(65536); System.out.println(i); // 65536 i = i.squareOf(); System.out.println(i); // 4294967296 i = i.squareOf(); System.out.println(i); // 18446744073709551616 i = i.squareOf(); System.out.println(i); // 340282366920938463463374607431768211456 i = i.squareOf(); System.out.println(i); // 115792089237316195423570985008687907853 // 269984665640564039457584007913129639936 MyBigInteger j = new MyBigInteger(1); j.plus(i); System.out.println(j); // 115792089237316195423570985008687907853 // 269984665640564039457584007913129639937[When they're printed via
System.out.println
,
MyBigInteger
s are displayed in decimal, as implied
by the specification of toString
in MyNumber
.]
[In its internal storage, a MyBigInteger
is free to use any radix
that is convenient.]
Constructor Summary | |
MyBigInteger(int i)
Constructs a new MyBigInteger object that initially stores
the integer value i . |
Method Summary | |
java.lang.Object |
clone()
Returns a new MyNumber object that initially
equals this . |
MyNumber |
createCompatible(int i)
Returns a new MyNumber object that initially holds
the value i . |
boolean |
divides(MyIntegralNumber n)
Returns true if n is evenly divisible by this . |
boolean |
equals(java.lang.Object o)
Tests whether o and this are equal. |
boolean |
lessThan(MyNumber n)
Returns true if this is smaller than
n . |
void |
minus()
Replaces this with -this . |
void |
plus(MyNumber n)
Replaces this with this + n . |
MyNumber |
squareOf()
Returns a new object holding the square of the value of this . |
void |
times(MyNumber n)
Replaces this with this * n . |
java.lang.String |
toString()
Retrieves the decimal representation of the stored integer. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public MyBigInteger(int i)
MyBigInteger
object that initially stores
the integer value i
.i
- the integer value to initially store in the new objectMethod Detail |
public java.lang.Object clone()
MyNumber
object that initially
equals this
.
[The returned object is guaranteed to be an instance of
this
's class.]
MyNumber
(of the same class as
this
) that takes this
's
integer value as its initial stored valuepublic MyNumber createCompatible(int i)
MyNumber
object that initially holds
the value i
.
[The returned object is guaranteed to be an instance of
this
's class.]
Example:
// construct n... MyNumber n = new MyInteger(3); // increment n... MyNumber one = n.createCompatible(1); // ...one is a MyInteger. n.plus(one);[The behavior of the
createCompatible
method is
undefined if i
is too large (or too small) to be
handled by this
's variety of number.]MyNumber
(of the same class as
this
) that takes i
as its
initial stored valuepublic boolean lessThan(MyNumber n)
true
if this
is smaller than
n
.
[The behavior of the lessThan
method is undefined if
n
is not compatible with this
.]
n
- the number to compare against this
true
if this
is less than
n
; false
otherwisepublic boolean equals(java.lang.Object o)
o
and this
are equal.o
- the object to compare against this
true
if (1) o
is a MyNumber
that is compatible with this
and (2) o
and this
currently store the same integer value;
false
otherwisepublic void minus()
this
with -this
.public void plus(MyNumber n)
this
with this + n
.
[The behavior of the plus
method is undefined if
n
is not compatible with this
.]
n
- the number to be added to this
public MyNumber squareOf()
this
.
[The returned object is guaranteed to be an instance of
this
's class.]
MyNumber
object (of the same class
as this
) that initially stores the
square of this object's integer value.public void times(MyNumber n)
this
with this * n
.
[The behavior of the times
method is undefined if
n
is not compatible with this
.]
n
- the number by which this
is to be scaledpublic boolean divides(MyIntegralNumber n)
true
if n
is evenly divisible by this
.
[The divides
method's behavior is undefined when this
is zero.]
n
- the integral number to divide intotrue
if n
is divisible by
this
; false
otherwisepublic java.lang.String toString()
String
that represents the stored integer,
in decimal
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |