1 5 6 9 10 package java.math; 11 12 31 32 class SignedMutableBigInteger extends MutableBigInteger { 33 34 37 int sign = 1; 38 39 41 45 SignedMutableBigInteger() { 46 super(); 47 } 48 49 53 SignedMutableBigInteger(int val) { 54 super(val); 55 } 56 57 61 SignedMutableBigInteger(MutableBigInteger val) { 62 super(val); 63 } 64 65 67 70 void signedAdd(SignedMutableBigInteger addend) { 71 if (sign == addend.sign) 72 add(addend); 73 else 74 sign = sign * subtract(addend); 75 76 } 77 78 81 void signedAdd(MutableBigInteger addend) { 82 if (sign == 1) 83 add(addend); 84 else 85 sign = sign * subtract(addend); 86 87 } 88 89 92 void signedSubtract(SignedMutableBigInteger addend) { 93 if (sign == addend.sign) 94 sign = sign * subtract(addend); 95 else 96 add(addend); 97 98 } 99 100 103 void signedSubtract(MutableBigInteger addend) { 104 if (sign == 1) 105 sign = sign * subtract(addend); 106 else 107 add(addend); 108 if (intLen == 0) 109 sign = 1; 110 } 111 112 116 public String toString() { 117 BigInteger b = new BigInteger (this, sign); 118 return 119 b.toString(); 120 } 121 122 } 123 | Popular Tags |