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