001import java.math.BigInteger;
002
003/** Wrapper for {@code java.math.}{@link java.math.BigInteger}.
004  * Required for mixed arithmetic with {@code int} or {@code long} operands because {@code java.math.}{@link java.math.BigInteger}
005  * does not implement a {@link java.math.BigInteger#valueOf(long) BigInteger(long)} constructor.
006  * @see <a target="_top" href="../programmer_examples/MyFractionAlgebra_UserDefinedAlgebra.html">user defined algebra</a>
007  * @see <a target="_top" href="../programmer_examples/ProgrammerExamples.html#biginteger">BigIntegerAlgebra_Demo</a>
008  */
009public class BigIntegerAlgebra extends BigInteger
010{
011   static final boolean DEBUG = false;
012   
013// private BigInteger itsBigInteger = null;
014   
015
016   /** Constructs a new BigIntegerAlgebra object. */
017   public BigIntegerAlgebra( BigInteger value )
018   {
019   // itsBigInteger = value;
020      super( value.toByteArray() );
021   }
022
023   /** Constructs a new BigIntegerAlgebra object.<br>
024     * Required for mixed operations: int <i>op</i> BigInteger, BigInteger <i>op</i> int
025     */
026   public BigIntegerAlgebra( long value )
027   {
028   // itsBigInteger = BigInteger.valueOf( value );
029   // super( "" + value );
030      this( BigInteger.valueOf( value ) );
031   }
032
033
034// --- reflection methods ---
035
036// arithmetic methods are required to return BigIntegerAlgebra 
037
038   /** Calls {@link java.math.BigInteger#negate}. */
039   public BigIntegerAlgebra neg()
040   {
041      return new BigIntegerAlgebra( negate() );
042   }
043   
044   /** Adds {@code opnd} to this. <br>
045     * Calls {@link java.math.BigInteger#add}.
046     */
047   public BigIntegerAlgebra add( BigInteger opnd )
048   {
049      return new BigIntegerAlgebra( super.add( opnd ) );
050   }
051   
052   /** Subtracts {@code opnd} from this. <br>
053     * Calls {@link java.math.BigInteger#subtract(java.math.BigInteger)}.
054     */
055   public BigIntegerAlgebra sub( BigInteger opnd )
056   {
057      return new BigIntegerAlgebra( subtract( opnd ) );
058   }
059   
060   /** (Post)Multiplies this by {@code opnd}. <br>
061     * Calls {@link java.math.BigInteger#multiply}.
062     */
063   public BigIntegerAlgebra mul( BigInteger opnd )
064   {
065      return new BigIntegerAlgebra( multiply( opnd ) );
066   }
067
068   /** Divides this by {@code opnd}. <br>
069     * Calls {@link java.math.BigInteger#divide}.
070     */
071   public BigIntegerAlgebra div( BigInteger opnd )
072   {
073      return new BigIntegerAlgebra( divide( opnd ) );
074   }
075   
076   /** Returns the remainder of this divided by {@code opnd}. <br>
077     * Calls {@link java.math.BigInteger#remainder}.
078     */
079   public BigIntegerAlgebra remainder( BigInteger opnd )
080   {
081      return new BigIntegerAlgebra( super.remainder( opnd ) );
082   }
083   
084   /** Returns the power of {@code exponent} of this. <br>
085     * Calls {@link java.math.BigInteger#pow}.
086     */
087   public BigIntegerAlgebra pow( int exponent )
088   {
089      return new BigIntegerAlgebra( super.pow( exponent ) );
090   }
091
092
093// --- other reflection methods ---
094
095}