Debian Codegraph @

Source/Utilities/CMath.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CMath.h"
22
23
24 namespace Konclude {
25
26 namespace Utilities {
27
28
29
30 CMath::CMath() {
31 }
32
33
34 CMath::~CMath() {
35 }
36
37
38 qint64 CMath::log2(qint64 x) {
39 if(x<Q_INT64_C(0x100000000)){
40 // code from website http://www.ssw.uni-linz.ac.at/Teaching/Lectures/Sem/2002/reports/Priewasser/index.html
41 if(x<0x10000){
42 if(x<0x100){
43 if(x<0x10){
44 if(x<0x4){
45 if(x<0x2)
46 return 0;
47 else
48 return 1;
49 } else {
50 if(x<0x8)
51 return 2;
52 else
53 return 3;
54 }
55 } else {
56 if(x<0x40){
57 if(x<0x20)
58 return 4;
59 else
60 return 5;
61 } else {
62 if(x<0x80)
63 return 6;
64 else
65 return 7;
66 }
67 }
68 } else {
69 if(x<0x1000){
70 if(x<0x400){
71 if(x<0x200)
72 return 8;
73 else
74 return 9;
75 } else {
76 if(x<0x800)
77 return 10;
78 else
79 return 11;
80 }
81 } else {
82 if(x<0x4000){
83 if(x<0x2000)
84 return 12;
85 else
86 return 13;
87 } else {
88 if(x<0x8000)
89 return 14;
90 else
91 return 15;
92 }
93 }
94 }
95 } else {
96 if(x<0x1000000){
97 if(x<0x100000){
98 if(x<0x40000){
99 if(x<0x20000)
100 return 16;
101 else
102 return 17;
103 } else {
104 if(x<0x80000)
105 return 18;
106 else
107 return 19;
108 }
109 } else {
110 if(x<0x400000){
111 if(x<0x200000)
112 return 20;
113 else
114 return 21;
115 } else {
116 if(x<0x800000)
117 return 22;
118 else
119 return 23;
120 }
121 }
122 } else {
123 if(x<0x10000000){
124 if(x<0x4000000){
125 if(x<0x2000000)
126 return 24;
127 else
128 return 25;
129 } else {
130 if(x<0x8000000)
131 return 26;
132 else
133 return 27;
134 }
135 } else {
136 if(x<0x40000000){
137 if(x<0x20000000)
138 return 28;
139 else
140 return 29;
141 } else {
142 if(x<0x80000000)
143 return 30;
144 else
145 return 31;
146 }
147 }
148 }
149 }
150 } else {
151 return log2(x>>32)+32;
152 }
153 }
154
155
156
157 }; // end namespace Utilities
158
159 }; // end namespace Konclude