5 #ifndef DUNE_BIGUNSIGNEDINT_HH
6 #define DUNE_BIGUNSIGNEDINT_HH
46 enum {
bits=std::numeric_limits<unsigned short>::digits,
n=k/
bits+(k%
bits!=0),
60 void print (std::ostream& s)
const ;
106 bool operator< (const bigunsignedint<k>& x)
const;
109 bool operator<= (const bigunsignedint<k>& x)
const;
126 unsigned int touint()
const;
144 #endif // HAVE_DUNE_HASH
147 unsigned short digit[
n];
151 inline void assign(std::size_t x);
166 std::size_t x = std::abs(y);
178 int no=std::min(static_cast<int>(
n),
179 static_cast<int>(std::numeric_limits<std::size_t>::digits/
bits));
181 for(
int i=0; i<no; ++i) {
185 for (
unsigned int i=no; i<
n; i++) digit[i]=0;
192 return (digit[1]<<
bits)+digit[0];
198 int firstInZeroRange=
n;
199 for(
int i=
n-1; i>=0; --i)
204 int representableDigits=std::numeric_limits<double>::digits/
bits;
205 int lastInRepresentableRange=0;
206 if(representableDigits<firstInZeroRange)
207 lastInRepresentableRange=firstInZeroRange-representableDigits;
209 for(
int i=firstInZeroRange-1; i>=lastInRepresentableRange; --i)
210 val =val*(1<<
bits)+digit[i];
211 return val*(1<<(
bits*lastInRepresentableRange));
220 for (
int i=
n-1; i>=0; i--)
224 int current = (digit[i]>>(d*4))&0xF;
228 s << std::hex << current;
231 else if (!leading) s << std::hex << current;
233 if (leading) s <<
"0";
238 inline std::ostream& operator<< (std::ostream& s, const bigunsignedint<k>& x)
252 for (
unsigned int i=0; i<
n; i++)
254 int sum = ((int)digit[i]) + ((int)x.digit[i]) + overflow;
267 for (
unsigned int i=0; i<
n; i++)
269 int diff = ((int)digit[i]) - (((int)x.digit[i]) + overflow);
271 result.digit[i] = (
unsigned short) diff;
274 result.digit[i] = (
unsigned short) (diff+
bitmask);
286 for (
unsigned int m=0; m<
n; m++)
289 unsigned int overflow(0);
290 for (
unsigned int i=0; i<
n; i++)
292 unsigned int digitproduct = ((
unsigned int)digit[i])*((
unsigned int)x.digit[m])+overflow;
293 singleproduct.digit[i+m] = (
unsigned short) (digitproduct&
bitmask);
294 overflow = (digitproduct>>
bits)&bitmask;
296 finalproduct = finalproduct+singleproduct;
300 for (
unsigned int i=0; i<
n; i++) result.digit[i] = finalproduct.digit[i];
309 for (
unsigned int i=0; i<
n; i++)
311 int sum = ((int)digit[i]) + overflow;
358 for (
unsigned int i=0; i<
n; i++)
359 result.digit[i] = digit[i]&x.digit[i];
367 for (
unsigned int i=0; i<
n; i++)
368 result.digit[i] = digit[i]^x.digit[i];
376 for (
unsigned int i=0; i<
n; i++)
377 result.digit[i] = digit[i]|x.digit[i];
385 for (
unsigned int i=0; i<
n; i++)
386 result.digit[i] = ~digit[i];
397 for (
int i=
n-1-j; i>=0; i--)
398 result.digit[i+j] = digit[i];
402 for (
int i=
n-1; i>=0; i--)
404 unsigned int temp = result.digit[i];
406 result.digit[i] = (
unsigned short) (temp&
bitmask);
409 result.digit[i+1] = result.digit[i+1]|temp;
422 for (
unsigned int i=0; i<
n-j; i++)
423 result.digit[i] = digit[i+j];
427 for (
unsigned int i=0; i<
n; i++)
429 unsigned int temp = result.digit[i];
430 temp = temp<<(
bits-j);
433 result.digit[i-1] = result.digit[i-1] | (temp&
bitmask);
442 for (
unsigned int i=0; i<
n; i++)
443 if (digit[i]!=x.digit[i])
return true;
450 return !((*this)!=x);
456 for (
int i=
n-1; i>=0; i--)
457 if (digit[i]<x.digit[i])
return true;
458 else if (digit[i]>x.digit[i])
return false;
465 for (
int i=
n-1; i>=0; i--)
466 if (digit[i]<x.digit[i])
return true;
467 else if (digit[i]>x.digit[i])
return false;
474 return !((*this)<=x);
561 struct numeric_limits<Dune::bigunsignedint<k> >
564 static const bool is_specialized =
true;
574 for(std::size_t i=0; i < Dune::bigunsignedint<k>::n; ++i)
575 max_.digit[i]=std::numeric_limits<unsigned short>::max();
582 static const bool is_signed =
false;
583 static const bool is_integer =
true;
584 static const bool is_exact =
true;
585 static const int radix = 2;
597 static const int min_exponent = 0;
598 static const int min_exponent10 = 0;
599 static const int max_exponent = 0;
600 static const int max_exponent10 = 0;
602 static const bool has_infinity =
false;
603 static const bool has_quiet_NaN =
false;
604 static const bool has_signaling_NaN =
false;
606 static const float_denorm_style has_denorm = denorm_absent;
607 static const bool has_denorm_loss =
false;
629 static const bool is_iec559 =
false;
630 static const bool is_bounded =
true;
631 static const bool is_modulo =
true;
633 static const bool traps =
false;
634 static const bool tinyness_before =
false;
635 static const float_round_style round_style = round_toward_zero;