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;
bigunsignedint< k > operator~() const
bitwise komplement
Definition: bigunsignedint.hh:382
Portable very large unsigned integers.
Definition: bigunsignedint.hh:42
bigunsignedint()
Construct uninitialized.
Definition: bigunsignedint.hh:158
bool operator<=(const bigunsignedint< k > &x) const
less than or equal
Definition: bigunsignedint.hh:463
bigunsignedint< k > operator/(const bigunsignedint< k > &x) const
Definition: bigunsignedint.hh:319
Definition: bigunsignedint.hh:46
Definition: bigunsignedint.hh:47
Support for calculating hash values of objects.
Dune namespace.
Definition: alignment.hh:13
A few common exception classes.
bigunsignedint< k > operator|(const bigunsignedint< k > &x) const
bitwise or
Definition: bigunsignedint.hh:373
static Dune::bigunsignedint< k > quiet_NaN()
Definition: bigunsignedint.hh:614
static Dune::bigunsignedint< k > epsilon()
Definition: bigunsignedint.hh:587
void print(std::ostream &s) const
Print number in hex notation.
Definition: bigunsignedint.hh:215
unsigned int touint() const
export to other types
Definition: bigunsignedint.hh:190
bigunsignedint< k > operator&(const bigunsignedint< k > &x) const
bitwise and
Definition: bigunsignedint.hh:355
static Dune::bigunsignedint< k > max()
Definition: bigunsignedint.hh:571
bigunsignedint< k > operator-(const bigunsignedint< k > &x) const
subtract
Definition: bigunsignedint.hh:262
std::size_t hash_range(It first, It last)
Hashes all elements in the range [first,last) and returns the combined hash.
Definition: hash.hh:449
static Dune::bigunsignedint< k > infinity()
Definition: bigunsignedint.hh:609
bool operator>=(const bigunsignedint< k > &x) const
greater or equal
Definition: bigunsignedint.hh:478
bigunsignedint< k > & operator++()
prefix increment
Definition: bigunsignedint.hh:305
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:29
Definition: bigunsignedint.hh:48
Definition: bigunsignedint.hh:47
bigunsignedint< k > operator*(const bigunsignedint< k > &x) const
multiply
Definition: bigunsignedint.hh:282
static Dune::bigunsignedint< k > denorm_min()
Definition: bigunsignedint.hh:624
#define DUNE_HASH_TYPE(...)
Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH.
Definition: hash.hh:143
bool operator==(const bigunsignedint< k > &x) const
equal
Definition: bigunsignedint.hh:448
Default exception class for mathematical errors.
Definition: exceptions.hh:267
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
bigunsignedint< k > operator<<(int i) const
left shift1/
Definition: bigunsignedint.hh:391
Definition: bigunsignedint.hh:46
double todouble() const
Convert to a double.
Definition: bigunsignedint.hh:196
bigunsignedint< k > operator^(const bigunsignedint< k > &x) const
bitwise exor
Definition: bigunsignedint.hh:364
bool operator<(const bigunsignedint< k > &x) const
less than
Definition: bigunsignedint.hh:454
static Dune::bigunsignedint< k > min()
Definition: bigunsignedint.hh:566
bigunsignedint< k > operator%(const bigunsignedint< k > &x) const
Definition: bigunsignedint.hh:338
bigunsignedint< k > operator>>(int i) const
right shift
Definition: bigunsignedint.hh:416
#define DUNE_DEFINE_HASH(template_args, type)
Defines the required struct specialization to make type hashable via Dune::hash.
Definition: hash.hh:126
bool operator>(const bigunsignedint< k > &x) const
greater than
Definition: bigunsignedint.hh:472
bigunsignedint< k > operator+(const bigunsignedint< k > &x) const
add
Definition: bigunsignedint.hh:247
Definition: bigunsignedint.hh:47
static Dune::bigunsignedint< k > round_error()
Definition: bigunsignedint.hh:592
bool operator!=(const bigunsignedint< k > &x) const
not equal
Definition: bigunsignedint.hh:440
static Dune::bigunsignedint< k > signaling_NaN()
Definition: bigunsignedint.hh:619
#define DUNE_HASH_TEMPLATE_ARGS(...)
Wrapper macro for the template arguments in DUNE_DEFINE_HASH.
Definition: hash.hh:135