1 module java.math.BigInteger; 2 3 import java.lang.all; 4 import java.util.Random; 5 version(Tango){ 6 import tango.math.BigInt; 7 } else { // Phobos 8 import std.bigint; 9 } 10 11 class BigInteger : Number { 12 13 static const BigInteger ZERO; 14 static const BigInteger ONE; 15 16 private BigInt bi; 17 18 static this(){ 19 ZERO = new BigInteger("0"); 20 ONE = new BigInteger("1"); 21 } 22 23 this(byte[] val){ 24 implMissing(__FILE__, __LINE__ ); 25 } 26 this(int signum, byte[] magnitude){ 27 implMissing(__FILE__, __LINE__ ); 28 } 29 this(int bitLength, int certainty, Random rnd){ 30 implMissing(__FILE__, __LINE__ ); 31 } 32 this(int numBits, Random rnd){ 33 implMissing(__FILE__, __LINE__ ); 34 } 35 this(String val){ 36 bi = BigInt( val ); 37 } 38 this(String val, int radix){ 39 getDwtLogger.error( __FILE__, __LINE__, "this({}, {})", val, radix ); 40 if( radix is 10 ){ 41 bi = BigInt( val ); 42 } 43 else if( radix is 16 ){ 44 bi = BigInt( "0x" ~ val ); 45 } 46 else { 47 implMissing(__FILE__, __LINE__ ); 48 } 49 } 50 private this( BigInt v ){ 51 bi = v; 52 } 53 private this( BigInteger v ){ 54 bi = v.bi; 55 } 56 private this( long v ){ 57 getDwtLogger.error( __FILE__, __LINE__, "this({})", v ); 58 bi = BigInt(v); 59 } 60 BigInteger abs(){ 61 implMissing(__FILE__, __LINE__ ); 62 return null; 63 } 64 BigInteger add(BigInteger val){ 65 implMissing(__FILE__, __LINE__ ); 66 return null; 67 } 68 BigInteger and(BigInteger val){ 69 implMissing(__FILE__, __LINE__ ); 70 return null; 71 } 72 BigInteger andNot(BigInteger val){ 73 implMissing(__FILE__, __LINE__ ); 74 return null; 75 } 76 int bitCount(){ 77 implMissing(__FILE__, __LINE__ ); 78 return 0; 79 } 80 int bitLength(){ 81 getDwtLogger.error( __FILE__, __LINE__, "bitLength()" ); 82 //implMissing(__FILE__, __LINE__ ); 83 return 0; 84 } 85 BigInteger clearBit(int n){ 86 implMissing(__FILE__, __LINE__ ); 87 return null; 88 } 89 int compareTo(BigInteger val){ 90 implMissing(__FILE__, __LINE__ ); 91 return 0; 92 } 93 int compareTo(Object o){ 94 implMissing(__FILE__, __LINE__ ); 95 return 0; 96 } 97 BigInteger divide(BigInteger val){ 98 implMissing(__FILE__, __LINE__ ); 99 return null; 100 } 101 BigInteger[] divideAndRemainder(BigInteger val){ 102 implMissing(__FILE__, __LINE__ ); 103 return null; 104 } 105 override 106 double doubleValue(){ 107 implMissing(__FILE__, __LINE__ ); 108 return 0; 109 } 110 bool equals(Object x){ 111 implMissing(__FILE__, __LINE__ ); 112 return 0; 113 } 114 BigInteger flipBit(int n){ 115 implMissing(__FILE__, __LINE__ ); 116 return null; 117 } 118 override 119 float floatValue(){ 120 implMissing(__FILE__, __LINE__ ); 121 return 0; 122 } 123 BigInteger gcd(BigInteger val){ 124 implMissing(__FILE__, __LINE__ ); 125 return null; 126 } 127 int getLowestSetBit(){ 128 implMissing(__FILE__, __LINE__ ); 129 return 0; 130 } 131 int hashCode(){ 132 implMissing(__FILE__, __LINE__ ); 133 return 0; 134 } 135 override 136 int intValue(){ 137 implMissing(__FILE__, __LINE__ ); 138 return 0; 139 } 140 bool isProbablePrime(int certainty){ 141 implMissing(__FILE__, __LINE__ ); 142 return 0; 143 } 144 override 145 long longValue(){ 146 version(Tango){ 147 getDwtLogger.error( __FILE__, __LINE__, "{}", bi.toHex ); 148 long res = 0; 149 auto txt = bi.toHex; 150 bool sign = false; 151 if( txt[0] is '-' ){ 152 sign = true; 153 txt = txt[1 .. $]; 154 } 155 int nibbles = 0; 156 foreach( uint idx, char c; txt ){ 157 if( c is '_' ) continue; 158 void addNibble( int v ){ 159 res <<= 4; 160 res |= v; 161 nibbles++; 162 } 163 if( c >= '0' && c <= '9' ) { 164 addNibble( c - '0' ); 165 } 166 else if( c >= 'a' && c <= 'f' ) { 167 addNibble( c - 'a' + 10 ); 168 } 169 else if( c >= 'A' && c <= 'F' ) { 170 addNibble( c - 'A' + 10 ); 171 } 172 else{ 173 getDwtLogger.error( __FILE__, __LINE__, "unknown char {} @{}", c, idx ); 174 } 175 } 176 if( nibbles > 16 ){ 177 getDwtLogger.error( __FILE__, __LINE__, "too much nibbles {}", nibbles ); 178 } 179 return res; 180 } else { // Phobos 181 return bi.toLong(); 182 } 183 } 184 BigInteger max(BigInteger val){ 185 implMissing(__FILE__, __LINE__ ); 186 return null; 187 } 188 BigInteger min(BigInteger val){ 189 implMissing(__FILE__, __LINE__ ); 190 return null; 191 } 192 BigInteger mod(BigInteger m){ 193 implMissing(__FILE__, __LINE__ ); 194 return null; 195 } 196 BigInteger modInverse(BigInteger m){ 197 implMissing(__FILE__, __LINE__ ); 198 return null; 199 } 200 BigInteger modPow(BigInteger exponent, BigInteger m){ 201 implMissing(__FILE__, __LINE__ ); 202 return null; 203 } 204 BigInteger multiply(BigInteger val){ 205 auto res = new BigInteger(this); 206 res.bi *= val.bi; 207 return res; 208 } 209 BigInteger negate(){ 210 implMissing(__FILE__, __LINE__ ); 211 return null; 212 } 213 BigInteger not(){ 214 implMissing(__FILE__, __LINE__ ); 215 return null; 216 } 217 BigInteger or(BigInteger val){ 218 implMissing(__FILE__, __LINE__ ); 219 return null; 220 } 221 BigInteger pow(int exponent){ 222 if( exponent < 0 ){ 223 throw new ArithmeticException("Negative exponent"); 224 } 225 version(Tango){ 226 if( bi.isZero() ){ 227 return exponent is 0 ? ONE : this; 228 } 229 } else { // Phobos 230 if( bi == 0 ){ 231 return exponent is 0 ? cast(BigInteger)ONE : this; 232 } 233 } 234 auto a = bi; 235 while(exponent>0){ 236 a *= bi; 237 exponent--; 238 } 239 return new BigInteger(a); 240 } 241 static BigInteger probablePrime(int bitLength, Random rnd){ 242 implMissing(__FILE__, __LINE__ ); 243 return null; 244 } 245 BigInteger remainder(BigInteger val){ 246 implMissing(__FILE__, __LINE__ ); 247 return null; 248 } 249 BigInteger setBit(int n){ 250 implMissing(__FILE__, __LINE__ ); 251 return null; 252 } 253 BigInteger shiftLeft(int n){ 254 implMissing(__FILE__, __LINE__ ); 255 return null; 256 } 257 BigInteger shiftRight(int n){ 258 implMissing(__FILE__, __LINE__ ); 259 return null; 260 } 261 int signum(){ 262 version(Tango) { 263 if( bi.isZero() ) return 0; 264 if( bi.isNegative() ) return -1; 265 } else { // Phobos 266 if( bi == 0 ) return 0; 267 if( bi < 0 ) return -1; 268 } 269 return 1; 270 } 271 BigInteger subtract(BigInteger val){ 272 implMissing(__FILE__, __LINE__ ); 273 return null; 274 } 275 bool testBit(int n){ 276 implMissing(__FILE__, __LINE__ ); 277 return 0; 278 } 279 byte[] toByteArray(){ 280 implMissing(__FILE__, __LINE__ ); 281 return null; 282 } 283 override 284 String toString(){ 285 implMissing(__FILE__, __LINE__ ); 286 return null; 287 } 288 String toString(int radix){ 289 implMissing(__FILE__, __LINE__ ); 290 return null; 291 } 292 static BigInteger valueOf(long val){ 293 auto res = new BigInteger(val); 294 return res; 295 } 296 BigInteger xor(BigInteger val){ 297 implMissing(__FILE__, __LINE__ ); 298 return null; 299 } 300 301 }