]> www.ginac.de Git - cln.git/blob - src/integer/conv/cl_I_cached_power.h
2006-04-25 Bruno Haible <bruno@clisp.org>
[cln.git] / src / integer / conv / cl_I_cached_power.h
1 // cached_power().\r
2 \r
3 // General includes.\r
4 #include "cl_sysdep.h"\r
5 \r
6 // Specification.\r
7 #include "cl_I.h"\r
8 \r
9 \r
10 // Implementation.\r
11 \r
12 namespace cln {\r
13 \r
14 // Table: For each base b (2 <= b <= 36), store k and b^k where k is the largest\r
15 // integer such that b^k < 2^intDsize, i.e. k == floor(log(2^intDsize-1,b)).\r
16 struct power_table_entry {\r
17         uintC k;\r
18         uintD b_to_the_k;\r
19 };\r
20 extern const power_table_entry power_table [36-2+1];\r
21 \r
22 // Table: contains for each base b (2 <= b <= 36) either NULL or an array of\r
23 // lazily computed b^(k*2^i) and maybe 1/b^(k*2^i).\r
24 //#define MUL_REPLACES_DIV\r
25 struct cached_power_table_entry {\r
26         ALLOCATE_ANYWHERE(cached_power_table_entry)\r
27         cl_I base_pow; // 0 or b^(k*2^i)\r
28 #ifdef MUL_REPLACES_DIV\r
29         cl_I inv_base_pow; // if base_pow: floor(2^(2*integer_length(base_pow))/base_pow)\r
30 #endif\r
31 };\r
32 \r
33 struct cached_power_table {\r
34         cached_power_table_entry element[40];\r
35         // Constructor and destructor - nothing special.\r
36         cached_power_table () {}\r
37         ~cached_power_table () {}\r
38         // Allocation and deallocation.\r
39         void* operator new (size_t size) { return malloc_hook(size); }\r
40         void operator delete (void* ptr) { free_hook(ptr); }\r
41 };\r
42 \r
43 extern cached_power_table* ctable [36-2+1];\r
44 \r
45 const cached_power_table_entry * cached_power (uintD base, uintL i);\r
46 \r
47 }  // namespace cln\r