3 #ifndef DUNE_BIGUNSIGNEDINT_HH
4 #define DUNE_BIGUNSIGNEDINT_HH
43 enum {
bits=std::numeric_limits<unsigned short>::digits,
n=k/
bits+(k%
bits!=0),
57 void print (std::ostream& s)
const ;
103 bool operator< (const bigunsignedint<k>& x)
const;
106 bool operator<= (const bigunsignedint<k>& x)
const;
123 unsigned int touint()
const;
135 unsigned short digit[
n];
139 inline void assign(std::size_t x);
154 std::size_t x = std::abs(y);
166 int no=std::min(static_cast<int>(
n),
167 static_cast<int>(std::numeric_limits<std::size_t>::digits/
bits));
169 for(
int i=0; i<no; ++i){
173 for (
unsigned int i=no; i<
n; i++) digit[i]=0;
180 return (digit[1]<<
bits)+digit[0];
186 int firstInZeroRange=
n;
187 for(
int i=
n-1; i>=0; --i)
192 int representableDigits=std::numeric_limits<double>::digits/
bits;
193 int lastInRepresentableRange=0;
194 if(representableDigits<firstInZeroRange)
195 lastInRepresentableRange=firstInZeroRange-representableDigits;
197 for(
int i=firstInZeroRange-1; i>=lastInRepresentableRange; --i)
198 val =val*(1<<
bits)+digit[i];
199 return val*(1<<(
bits*lastInRepresentableRange));
208 for (
int i=
n-1; i>=0; i--)
212 int current = (digit[i]>>(d*4))&0xF;
216 s << std::hex << current;
219 else if (!leading) s << std::hex << current;
221 if (leading) s <<
"0";
226 inline std::ostream& operator<< (std::ostream& s, const bigunsignedint<k>& x)
240 for (
unsigned int i=0; i<
n; i++)
242 int sum = ((int)digit[i]) + ((int)x.digit[i]) + overflow;
255 for (
unsigned int i=0; i<
n; i++)
257 int diff = ((int)digit[i]) - (((int)x.digit[i]) + overflow);
259 result.digit[i] = (
unsigned short) diff;
262 result.digit[i] = (
unsigned short) (diff+
bitmask);
274 for (
unsigned int m=0; m<
n; m++)
277 unsigned int overflow(0);
278 for (
unsigned int i=0; i<
n; i++)
280 unsigned int digitproduct = ((
unsigned int)digit[i])*((
unsigned int)x.digit[m])+overflow;
281 singleproduct.digit[i+m] = (
unsigned short) (digitproduct&
bitmask);
282 overflow = (digitproduct>>
bits)&bitmask;
284 finalproduct = finalproduct+singleproduct;
288 for (
unsigned int i=0; i<
n; i++) result.digit[i] = finalproduct.digit[i];
297 for (
unsigned int i=0; i<
n; i++)
299 int sum = ((int)digit[i]) + overflow;
346 for (
unsigned int i=0; i<
n; i++)
347 result.digit[i] = digit[i]&x.digit[i];
355 for (
unsigned int i=0; i<
n; i++)
356 result.digit[i] = digit[i]^x.digit[i];
364 for (
unsigned int i=0; i<
n; i++)
365 result.digit[i] = digit[i]|x.digit[i];
373 for (
unsigned int i=0; i<
n; i++)
374 result.digit[i] = ~digit[i];
385 for (
int i=
n-1-j; i>=0; i--)
386 result.digit[i+j] = digit[i];
390 for (
int i=
n-1; i>=0; i--)
392 unsigned int temp = result.digit[i];
394 result.digit[i] = (
unsigned short) (temp&
bitmask);
397 result.digit[i+1] = result.digit[i+1]|temp;
410 for (
unsigned int i=0; i<
n-j; i++)
411 result.digit[i] = digit[i+j];
415 for (
unsigned int i=0; i<
n; i++)
417 unsigned int temp = result.digit[i];
418 temp = temp<<(
bits-j);
421 result.digit[i-1] = result.digit[i-1] | (temp&
bitmask);
430 for (
unsigned int i=0; i<
n; i++)
431 if (digit[i]!=x.digit[i])
return true;
438 return !((*this)!=x);
444 for (
int i=
n-1; i>=0; i--)
445 if (digit[i]<x.digit[i])
return true;
446 else if (digit[i]>x.digit[i])
return false;
453 for (
int i=
n-1; i>=0; i--)
454 if (digit[i]<x.digit[i])
return true;
455 else if (digit[i]>x.digit[i])
return false;
462 return !((*this)<=x);
549 struct numeric_limits<Dune::bigunsignedint<k> >
552 static const bool is_specialized =
true;
562 for(std::size_t i=0; i < Dune::bigunsignedint<k>::n; ++i)
563 max_.digit[i]=std::numeric_limits<unsigned short>::max();
570 static const bool is_signed =
false;
571 static const bool is_integer =
true;
572 static const bool is_exact =
true;
573 static const int radix = 2;
585 static const int min_exponent = 0;
586 static const int min_exponent10 = 0;
587 static const int max_exponent = 0;
588 static const int max_exponent10 = 0;
590 static const bool has_infinity =
false;
591 static const bool has_quiet_NaN =
false;
592 static const bool has_signaling_NaN =
false;
594 static const float_denorm_style has_denorm = denorm_absent;
595 static const bool has_denorm_loss =
false;
617 static const bool is_iec559 =
false;
618 static const bool is_bounded =
true;
619 static const bool is_modulo =
true;
621 static const bool traps =
false;
622 static const bool tinyness_before =
false;
623 static const float_round_style round_style = round_toward_zero;