29 #ifndef REAL_INFININT_HPP 30 #define REAL_INFININT_HPP 32 #include "../my_config.h" 37 #include <sys/types.h> 48 #define ZEROED_SIZE 50 53 class user_interaction;
63 #if SIZEOF_OFF_T > SIZEOF_TIME_T 64 #if SIZEOF_OFF_T > SIZEOF_SIZE_T 66 { infinint_from(a); };
69 { infinint_from(a); };
72 #if SIZEOF_TIME_T > SIZEOF_SIZE_T 74 { infinint_from(a); };
77 { infinint_from(a); };
91 { detruit(); copy_from(ref);
return *
this; };
94 void read(
generic_file &f) { detruit(); build_from_file(f); };
98 infinint & operator *= (
unsigned char arg);
100 template <
class T>
infinint power(
const T & exponent)
const;
111 {
infinint ret = *
this; ++(*this);
return ret; };
113 {
infinint ret = *
this; --(*this);
return ret; };
115 {
return *
this += 1; };
117 {
return *
this -= 1; };
119 U_32 operator % (U_32 arg)
const 120 {
return modulo(arg); };
125 template <
class T>
void unstack(T &v)
126 { infinint_unstack_to(v); }
128 infinint get_storage_size()
const {
return field->size(); };
131 unsigned char operator [] (
const infinint & position)
const;
134 bool is_zero()
const;
144 static bool is_system_big_endian();
147 static const int TG = 4;
149 enum endian { big_endian, little_endian, not_initialized };
150 typedef unsigned char group[TG];
154 bool is_valid()
const;
157 void copy_from(
const infinint & ref);
159 void make_at_least_as_wider_as(
const infinint & ref);
160 template <
class T>
void infinint_from(T a);
161 template <
class T> T max_val_of(T x);
162 template <
class T>
void infinint_unstack_to(T &a);
163 template <
class T> T modulo(T arg)
const;
164 signed int difference(
const infinint & b)
const;
169 static endian used_endian;
170 static U_8 zeroed_field[ZEROED_SIZE];
171 static void setup_endian();
175 #define OPERATOR(OP) inline bool operator OP (const infinint &a, const infinint &b) \ 177 return a.difference(b) OP 0; \ 202 template <
class T>
inline void euclide(T a, T b, T & q, T &r)
224 template <
class T>
infinint infinint::power(
const T & exponent)
const 227 for(T count = 0; count < exponent; ++count)
233 template <
class T> T infinint::modulo(T arg)
const 237 unsigned char *debut = (
unsigned char *)(&ret);
238 unsigned char *ptr = debut +
sizeof(T) - 1;
239 storage::iterator it = tmp.field->rbegin();
241 while(it != tmp.field->rend() && ptr >= debut)
250 while(it != tmp.field->rend())
257 if(used_endian == little_endian)
258 int_tools_swap_bytes(debut,
sizeof(T));
264 template <
class T>
void infinint::infinint_from(T a)
266 U_I size =
sizeof(a);
268 unsigned char *ptr, *fin;
270 if(used_endian == not_initialized)
273 if(used_endian == little_endian)
276 ptr = (
unsigned char *)(&a) + (size - 1);
277 fin = (
unsigned char *)(&a) - 1;
282 ptr = (
unsigned char *)(&a);
283 fin = (
unsigned char *)(&a) + size;
286 while(ptr != fin && *ptr == 0)
298 field =
new (std::nothrow)
storage(size);
301 storage::iterator it = field->begin();
309 if(it != field->end())
313 throw Ememory(
"template infinint::infinint_from");
316 template <
class T> T infinint::max_val_of(T x)
324 x = int_tools_rotate_right_one_bit(x);
331 template <
class T>
void infinint::infinint_unstack_to(T &a)
336 static const T max_T = max_val_of(a);
342 unsigned char *debut = (
unsigned char *)&transfert;
343 unsigned char *ptr = debut +
sizeof(transfert) - 1;
344 storage::iterator it = field->rbegin();
346 while(ptr >= debut && it != field->rend())
353 if(used_endian == little_endian)
354 int_tools_swap_bytes(debut,
sizeof(transfert));
are defined here basic integer types that tend to be portable
contains a class that permits arbitrary large data storage
exception used when memory has been exhausted
arbitrary large storage structure
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
this is the interface class from which all other data transfer classes inherit
this is the base class of object that can be allocated on a memory pool
the arbitrary large positive integer class
libdar namespace encapsulate all libdar symbols