comparison base/src/java/math/BigInteger.d @ 99:5d5bd660917f

build some databind snippets
author Frank Benoit <benoit@tionex.de>
date Wed, 22 Apr 2009 18:59:26 +0200
parents 48d4ee626868
children 9f4c18c268b2
comparison
equal deleted inserted replaced
98:48d4ee626868 99:5d5bd660917f
33 } 33 }
34 this(String val){ 34 this(String val){
35 bi = BigInt( val ); 35 bi = BigInt( val );
36 } 36 }
37 this(String val, int radix){ 37 this(String val, int radix){
38 getDwtLogger.error( __FILE__, __LINE__, "this({}, {})", val, radix );
38 if( radix is 10 ){ 39 if( radix is 10 ){
39 bi = BigInt( val ); 40 bi = BigInt( val );
40 } 41 }
41 else if( radix is 16 ){ 42 else if( radix is 16 ){
42 bi = BigInt( "0x" ~ val ); 43 bi = BigInt( "0x" ~ val );
44 else { 45 else {
45 implMissing(__FILE__, __LINE__ ); 46 implMissing(__FILE__, __LINE__ );
46 } 47 }
47 } 48 }
48 private this( BigInt v ){ 49 private this( BigInt v ){
50 getDwtLogger.error( __FILE__, __LINE__, "this({})", v.toHex );
49 bi = v; 51 bi = v;
50 } 52 }
51 private this( BigInteger v ){ 53 private this( BigInteger v ){
54 getDwtLogger.error( __FILE__, __LINE__, "this({})", bi.toHex );
52 bi = v.bi; 55 bi = v.bi;
53 } 56 }
54 private this( long v ){ 57 private this( long v ){
58 getDwtLogger.error( __FILE__, __LINE__, "this({})", v );
55 bi = BigInt(v); 59 bi = BigInt(v);
56 } 60 }
57 BigInteger abs(){ 61 BigInteger abs(){
58 implMissing(__FILE__, __LINE__ ); 62 implMissing(__FILE__, __LINE__ );
59 return null; 63 return null;
73 int bitCount(){ 77 int bitCount(){
74 implMissing(__FILE__, __LINE__ ); 78 implMissing(__FILE__, __LINE__ );
75 return 0; 79 return 0;
76 } 80 }
77 int bitLength(){ 81 int bitLength(){
82 getDwtLogger.error( __FILE__, __LINE__, "bitLength()" );
78 //implMissing(__FILE__, __LINE__ ); 83 //implMissing(__FILE__, __LINE__ );
79 return 0; 84 return 0;
80 } 85 }
81 BigInteger clearBit(int n){ 86 BigInteger clearBit(int n){
82 implMissing(__FILE__, __LINE__ ); 87 implMissing(__FILE__, __LINE__ );
133 bool isProbablePrime(int certainty){ 138 bool isProbablePrime(int certainty){
134 implMissing(__FILE__, __LINE__ ); 139 implMissing(__FILE__, __LINE__ );
135 return 0; 140 return 0;
136 } 141 }
137 long longValue(){ 142 long longValue(){
138 implMissing(__FILE__, __LINE__ ); 143 getDwtLogger.error( __FILE__, __LINE__, "{}", bi.toHex );
139 return 0; 144 long res = 0;
145 auto txt = bi.toHex;
146 bool sign = false;
147 if( txt[0] is '-' ){
148 sign = true;
149 txt = txt[1 .. $];
150 }
151 int nibbles = 0;
152 foreach( uint idx, char c; txt ){
153 if( c is '_' ) continue;
154 void addNibble( int v ){
155 res <<= 4;
156 res |= v;
157 nibbles++;
158 }
159 if( c >= '0' && c <= '9' ) {
160 addNibble( c - '0' );
161 }
162 else if( c >= 'a' && c <= 'f' ) {
163 addNibble( c - 'a' + 10 );
164 }
165 else if( c >= 'A' && c <= 'F' ) {
166 addNibble( c - 'A' + 10 );
167 }
168 else{
169 getDwtLogger.error( __FILE__, __LINE__, "unknown char {} @{}", c, idx );
170 }
171 }
172 if( nibbles > 16 ){
173 getDwtLogger.error( __FILE__, __LINE__, "too much nibbles {}", nibbles );
174 }
175 return res;
140 } 176 }
141 BigInteger max(BigInteger val){ 177 BigInteger max(BigInteger val){
142 implMissing(__FILE__, __LINE__ ); 178 implMissing(__FILE__, __LINE__ );
143 return null; 179 return null;
144 } 180 }
157 BigInteger modPow(BigInteger exponent, BigInteger m){ 193 BigInteger modPow(BigInteger exponent, BigInteger m){
158 implMissing(__FILE__, __LINE__ ); 194 implMissing(__FILE__, __LINE__ );
159 return null; 195 return null;
160 } 196 }
161 BigInteger multiply(BigInteger val){ 197 BigInteger multiply(BigInteger val){
198 getDwtLogger.error( __FILE__, __LINE__, "multiply ({})", val.bi.toHex );
162 auto res = new BigInteger(this); 199 auto res = new BigInteger(this);
163 res.bi *= val.bi; 200 res.bi *= val.bi;
164 return res; 201 return res;
165 } 202 }
166 BigInteger negate(){ 203 BigInteger negate(){