SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
big_integer_base.hpp
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
30 #ifndef BIG_INTEGER_BASE_IMPLEMENTATION_GUARD
31 #define BIG_INTEGER_BASE_IMPLEMENTATION_GUARD
32 
33 namespace SeComLib {
34 namespace Core {
35  /* Constructors */
36 
40  template <typename T_Impl>
42  T_Impl::Initialize(*this);
43  }
44 
48  template <typename T_Impl>
50  T_Impl::Initialize(*this, input);
51  }
52 
56  template <typename T_Impl>
57  inline BigIntegerBase<T_Impl>::BigIntegerBase (const long input) {
58  T_Impl::Initialize(*this, input);
59  }
60 
64  template <typename T_Impl>
65  inline BigIntegerBase<T_Impl>::BigIntegerBase (const unsigned long input) {
66  T_Impl::Initialize(*this, input);
67  }
68 
72  template <typename T_Impl>
73  inline BigIntegerBase<T_Impl>::BigIntegerBase (const int input) {
74  T_Impl::Initialize(*this, static_cast<long>(input));
75  }
76 
80  template <typename T_Impl>
81  inline BigIntegerBase<T_Impl>::BigIntegerBase (const unsigned int input) {
82  T_Impl::Initialize(*this, static_cast<unsigned long>(input));
83  }
84 
90  template <typename T_Impl>
91  inline BigIntegerBase<T_Impl>::BigIntegerBase (const double input, const BigIntegerBase<T_Impl> &scaling, const bool truncate) {
92  T_Impl::Initialize(*this, input, scaling, truncate);
93  }
94 
100  template <typename T_Impl>
101  inline BigIntegerBase<T_Impl>::BigIntegerBase (const double input, const unsigned int numberOfDigits, const bool truncate) {
102  T_Impl::Initialize(*this, input, numberOfDigits, truncate);
103  }
104 
111  template <typename T_Impl>
112  inline BigIntegerBase<T_Impl>::BigIntegerBase (const std::string &input, const int base) {
113  T_Impl::Initialize(*this, input, base);
114  }
115 
116  /* /Constructors */
117 
121  template <typename T_Impl>
123  T_Impl::Destroy(*this);
124  }
125 
126  /* Operator overloading */
127 
134  template <typename T_Impl>
136  T_Impl::Set(*this, input);
137  return *this;
138  }
139 
144  template <typename T_Impl>
146  T_Impl::Set(*this, input);
147  return *this;
148  }
149 
154  template <typename T_Impl>
155  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator= (const unsigned long input) {
156  T_Impl::Set(*this, input);
157  return *this;
158  }
159 
164  template <typename T_Impl>
166  T_Impl::Set(*this, static_cast<long>(input));
167  return *this;
168  }
169 
174  template <typename T_Impl>
175  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator= (const unsigned int input) {
176  T_Impl::Set(*this, static_cast<unsigned long>(input));
177  return *this;
178  }
179 
183  template <typename T_Impl>
185  BigIntegerBase<T_Impl> output(*this);
186  return output;
187  }
188 
192  template <typename T_Impl>
194  BigIntegerBase<T_Impl> output;
195 
196  T_Impl::InvertSign(output, *this);
197 
198  return output;
199  }
200 
204  template <typename T_Impl>
206  T_Impl::Add(*this, *this, 1L);
207  return *this;
208  }
209 
213  template <typename T_Impl>
215  BigIntegerBase<T_Impl> output(*this);
216 
217  T_Impl::Add(*this, *this, 1L);
218 
219  return output;
220  }
221 
225  template <typename T_Impl>
227  T_Impl::Subtract(*this, *this, 1L);
228  return *this;
229  }
230 
234  template <typename T_Impl>
236  BigIntegerBase<T_Impl> output(*this);
237 
238  T_Impl::Subtract(*this, *this, 1L);
239 
240  return output;
241  }
242 
247  template <typename T_Impl>
249  BigIntegerBase<T_Impl> output;
250 
251  T_Impl::Add(output, *this, input);
252 
253  return output;
254  }
255 
260  template <typename T_Impl>
262  BigIntegerBase<T_Impl> output;
263 
264  T_Impl::Add(output, *this, input);
265 
266  return output;
267  }
268 
273  template <typename T_Impl>
274  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator+ (const unsigned long input) const {
275  BigIntegerBase<T_Impl> output;
276 
277  T_Impl::Add(output, *this, input);
278 
279  return output;
280  }
281 
286  template <typename T_Impl>
288  BigIntegerBase<T_Impl> output;
289 
290  T_Impl::Add(output, *this, static_cast<long>(input));
291 
292  return output;
293  }
294 
299  template <typename T_Impl>
300  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator+ (const unsigned int input) const {
301  BigIntegerBase<T_Impl> output;
302 
303  T_Impl::Add(output, *this, static_cast<unsigned long>(input));
304 
305  return output;
306  }
307 
312  template <typename T_Impl>
314  T_Impl::Add(*this, *this, input);
315  return *this;
316  }
317 
322  template <typename T_Impl>
324  T_Impl::Add(*this, *this, input);
325  return *this;
326  }
327 
332  template <typename T_Impl>
333  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator+= (const unsigned long input) {
334  T_Impl::Add(*this, *this, input);
335  return *this;
336  }
337 
342  template <typename T_Impl>
344  T_Impl::Add(*this, *this, static_cast<long>(input));
345  return *this;
346  }
347 
352  template <typename T_Impl>
354  T_Impl::Add(*this, *this, static_cast<unsigned long>(input));
355  return *this;
356  }
357 
362  template <typename T_Impl>
364  BigIntegerBase<T_Impl> output;
365 
366  T_Impl::Subtract(output, *this, input);
367 
368  return output;
369  }
370 
375  template <typename T_Impl>
377  BigIntegerBase<T_Impl> output;
378 
379  T_Impl::Subtract(output, *this, input);
380 
381  return output;
382  }
383 
388  template <typename T_Impl>
389  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator- (const unsigned long input) const {
390  BigIntegerBase<T_Impl> output;
391 
392  T_Impl::Subtract(output, *this, input);
393 
394  return output;
395  }
396 
401  template <typename T_Impl>
403  BigIntegerBase<T_Impl> output;
404 
405  T_Impl::Subtract(output, *this, static_cast<long>(input));
406 
407  return output;
408  }
409 
414  template <typename T_Impl>
415  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator- (const unsigned int input) const {
416  BigIntegerBase<T_Impl> output;
417 
418  T_Impl::Subtract(output, *this, static_cast<unsigned long>(input));
419 
420  return output;
421  }
422 
427  template <typename T_Impl>
429  T_Impl::Subtract(*this, *this, input);
430  return *this;
431  }
432 
437  template <typename T_Impl>
439  T_Impl::Subtract(*this, *this, input);
440  return *this;
441  }
442 
447  template <typename T_Impl>
448  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator-= (const unsigned long input) {
449  T_Impl::Subtract(*this, *this, input);
450  return *this;
451  }
452 
457  template <typename T_Impl>
459  T_Impl::Subtract(*this, *this, static_cast<long>(input));
460  return *this;
461  }
462 
467  template <typename T_Impl>
469  T_Impl::Subtract(*this, *this, static_cast<unsigned long>(input));
470  return *this;
471  }
472 
477  template <typename T_Impl>
479  BigIntegerBase<T_Impl> output;
480 
481  T_Impl::Multiply(output, *this, input);
482 
483  return output;
484  }
485 
490  template <typename T_Impl>
492  BigIntegerBase<T_Impl> output;
493 
494  T_Impl::Multiply(output, *this, input);
495 
496  return output;
497  }
498 
503  template <typename T_Impl>
504  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator* (const unsigned long input) const {
505  BigIntegerBase<T_Impl> output;
506 
507  T_Impl::Multiply(output, *this, input);
508 
509  return output;
510  }
511 
516  template <typename T_Impl>
518  BigIntegerBase<T_Impl> output;
519 
520  T_Impl::Multiply(output, *this, static_cast<long>(input));
521 
522  return output;
523  }
524 
529  template <typename T_Impl>
530  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator* (const unsigned int input) const {
531  BigIntegerBase<T_Impl> output;
532 
533  T_Impl::Multiply(output, *this, static_cast<unsigned long>(input));
534 
535  return output;
536  }
537 
542  template <typename T_Impl>
544  T_Impl::Multiply(*this, *this, input);
545  return *this;
546  }
547 
552  template <typename T_Impl>
554  T_Impl::Multiply(*this, *this, input);
555  return *this;
556  }
557 
562  template <typename T_Impl>
563  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator*= (const unsigned long input) {
564  T_Impl::Multiply(*this, *this, input);
565  return *this;
566  }
567 
572  template <typename T_Impl>
574  T_Impl::Multiply(*this, *this, static_cast<long>(input));
575  return *this;
576  }
577 
582  template <typename T_Impl>
584  T_Impl::Multiply(*this, *this, static_cast<unsigned long>(input));
585  return *this;
586  }
587 
592  template <typename T_Impl>
594  BigIntegerBase<T_Impl> output;
595 
596  T_Impl::Divide(output, *this, input);
597 
598  return output;
599  }
600 
605  template <typename T_Impl>
607  BigIntegerBase<T_Impl> output;
608 
609  T_Impl::Divide(output, *this, input);
610 
611  return output;
612  }
613 
618  template <typename T_Impl>
619  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator/ (const unsigned long input) const {
620  BigIntegerBase<T_Impl> output;
621 
622  T_Impl::Divide(output, *this, input);
623 
624  return output;
625  }
626 
631  template <typename T_Impl>
633  BigIntegerBase<T_Impl> output;
634 
635  T_Impl::Divide(output, *this, static_cast<long>(input));
636 
637  return output;
638  }
639 
644  template <typename T_Impl>
645  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator/ (const unsigned int input) const {
646  BigIntegerBase<T_Impl> output;
647 
648  T_Impl::Divide(output, *this, static_cast<unsigned long>(input));
649 
650  return output;
651  }
652 
657  template <typename T_Impl>
659  T_Impl::Divide(*this, *this, input);
660  return *this;
661  }
662 
667  template <typename T_Impl>
669  T_Impl::Divide(*this, *this, input);
670  return *this;
671  }
672 
677  template <typename T_Impl>
678  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator/= (const unsigned long input) {
679  T_Impl::Divide(*this, *this, input);
680  return *this;
681  }
682 
687  template <typename T_Impl>
689  T_Impl::Divide(*this, *this, static_cast<long>(input));
690  return *this;
691  }
692 
697  template <typename T_Impl>
699  T_Impl::Divide(*this, *this, static_cast<unsigned long>(input));
700  return *this;
701  }
702 
707  template <typename T_Impl>
709  BigIntegerBase<T_Impl> output;
710 
711  T_Impl::Modulo(output, *this, input);
712 
713  return output;
714  }
715 
720  template <typename T_Impl>
722  BigIntegerBase<T_Impl> output;
723 
724  T_Impl::Modulo(output, *this, input);
725 
726  return output;
727  }
728 
733  template <typename T_Impl>
734  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator% (const unsigned long input) const {
735  BigIntegerBase<T_Impl> output;
736 
737  T_Impl::Modulo(output, *this, input);
738 
739  return output;
740  }
741 
746  template <typename T_Impl>
748  BigIntegerBase<T_Impl> output;
749 
750  T_Impl::Modulo(output, *this, static_cast<long>(input));
751 
752  return output;
753  }
754 
759  template <typename T_Impl>
760  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator% (const unsigned int input) const {
761  BigIntegerBase<T_Impl> output;
762 
763  T_Impl::Modulo(output, *this, static_cast<unsigned long>(input));
764 
765  return output;
766  }
767 
772  template <typename T_Impl>
774  T_Impl::Modulo(*this, *this, input);
775  return *this;
776  }
777 
782  template <typename T_Impl>
784  T_Impl::Modulo(*this, *this, input);
785  return *this;
786  }
787 
792  template <typename T_Impl>
793  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::operator%= (const unsigned long input) {
794  T_Impl::Modulo(*this, *this, input);
795  return *this;
796  }
797 
802  template <typename T_Impl>
804  T_Impl::Modulo(*this, *this, static_cast<long>(input));
805  return *this;
806  }
807 
812  template <typename T_Impl>
814  T_Impl::Modulo(*this, *this, static_cast<unsigned long>(input));
815  return *this;
816  }
817 
822  template <typename T_Impl>
824  return T_Impl::Compare(*this, input) == 0 ? true : false;
825  }
826 
831  template <typename T_Impl>
832  inline bool BigIntegerBase<T_Impl>::operator== (const long input) const {
833  return T_Impl::Compare(*this, input) == 0 ? true : false;
834  }
835 
840  template <typename T_Impl>
841  inline bool BigIntegerBase<T_Impl>::operator== (const unsigned long input) const {
842  return T_Impl::Compare(*this, input) == 0 ? true : false;
843  }
844 
849  template <typename T_Impl>
850  inline bool BigIntegerBase<T_Impl>::operator== (const int input) const {
851  return T_Impl::Compare(*this, static_cast<long>(input)) == 0 ? true : false;
852  }
853 
858  template <typename T_Impl>
859  inline bool BigIntegerBase<T_Impl>::operator== (const unsigned int input) const {
860  return T_Impl::Compare(*this, static_cast<unsigned long>(input)) == 0 ? true : false;
861  }
862 
867  template <typename T_Impl>
869  return T_Impl::Compare(*this, input) != 0 ? true : false;
870  }
871 
876  template <typename T_Impl>
877  inline bool BigIntegerBase<T_Impl>::operator!= (const long input) const {
878  return T_Impl::Compare(*this, input) != 0 ? true : false;
879  }
880 
885  template <typename T_Impl>
886  inline bool BigIntegerBase<T_Impl>::operator!= (const unsigned long input) const {
887  return T_Impl::Compare(*this, input) != 0 ? true : false;
888  }
889 
894  template <typename T_Impl>
895  inline bool BigIntegerBase<T_Impl>::operator!= (const int input) const {
896  return T_Impl::Compare(*this, static_cast<long>(input)) != 0 ? true : false;
897  }
898 
903  template <typename T_Impl>
904  inline bool BigIntegerBase<T_Impl>::operator!= (const unsigned int input) const {
905  return T_Impl::Compare(*this, static_cast<unsigned long>(input)) != 0 ? true : false;
906  }
907 
912  template <typename T_Impl>
914  return T_Impl::Compare(*this, input) < 0 ? true : false;
915  }
916 
921  template <typename T_Impl>
922  inline bool BigIntegerBase<T_Impl>::operator< (const long input) const {
923  return T_Impl::Compare(*this, input) < 0 ? true : false;
924  }
925 
930  template <typename T_Impl>
931  inline bool BigIntegerBase<T_Impl>::operator< (const unsigned long input) const {
932  return T_Impl::Compare(*this, input) < 0 ? true : false;
933  }
934 
939  template <typename T_Impl>
940  inline bool BigIntegerBase<T_Impl>::operator< (const int input) const {
941  return T_Impl::Compare(*this, static_cast<long>(input)) < 0 ? true : false;
942  }
943 
948  template <typename T_Impl>
949  inline bool BigIntegerBase<T_Impl>::operator< (const unsigned int input) const {
950  return T_Impl::Compare(*this, static_cast<unsigned long>(input)) < 0 ? true : false;
951  }
952 
957  template <typename T_Impl>
959  return T_Impl::Compare(*this, input) <= 0 ? true : false;
960  }
961 
966  template <typename T_Impl>
967  inline bool BigIntegerBase<T_Impl>::operator<= (const long input) const {
968  return T_Impl::Compare(*this, input) <= 0 ? true : false;
969  }
970 
975  template <typename T_Impl>
976  inline bool BigIntegerBase<T_Impl>::operator<= (const unsigned long input) const {
977  return T_Impl::Compare(*this, input) <= 0 ? true : false;
978  }
979 
984  template <typename T_Impl>
985  inline bool BigIntegerBase<T_Impl>::operator<= (const int input) const {
986  return T_Impl::Compare(*this, static_cast<long>(input)) <= 0 ? true : false;
987  }
988 
993  template <typename T_Impl>
994  inline bool BigIntegerBase<T_Impl>::operator<= (const unsigned int input) const {
995  return T_Impl::Compare(*this, static_cast<unsigned long>(input)) <= 0 ? true : false;
996  }
997 
1002  template <typename T_Impl>
1004  return T_Impl::Compare(*this, input) >= 0 ? true : false;
1005  }
1006 
1011  template <typename T_Impl>
1012  inline bool BigIntegerBase<T_Impl>::operator>= (const long input) const {
1013  return T_Impl::Compare(*this, input) >= 0 ? true : false;
1014  }
1015 
1020  template <typename T_Impl>
1021  inline bool BigIntegerBase<T_Impl>::operator>= (const unsigned long input) const {
1022  return T_Impl::Compare(*this, input) >= 0 ? true : false;
1023  }
1024 
1029  template <typename T_Impl>
1030  inline bool BigIntegerBase<T_Impl>::operator>= (const int input) const {
1031  return T_Impl::Compare(*this, static_cast<long>(input)) >= 0 ? true : false;
1032  }
1033 
1038  template <typename T_Impl>
1039  inline bool BigIntegerBase<T_Impl>::operator>= (const unsigned int input) const {
1040  return T_Impl::Compare(*this, static_cast<unsigned long>(input)) >= 0 ? true : false;
1041  }
1042 
1047  template <typename T_Impl>
1049  return T_Impl::Compare(*this, input) > 0 ? true : false;
1050  }
1051 
1056  template <typename T_Impl>
1057  inline bool BigIntegerBase<T_Impl>::operator> (const long input) const {
1058  return T_Impl::Compare(*this, input) > 0 ? true : false;
1059  }
1060 
1065  template <typename T_Impl>
1066  inline bool BigIntegerBase<T_Impl>::operator> (const unsigned long input) const {
1067  return T_Impl::Compare(*this, input) > 0 ? true : false;
1068  }
1069 
1074  template <typename T_Impl>
1075  inline bool BigIntegerBase<T_Impl>::operator> (const int input) const {
1076  return T_Impl::Compare(*this, static_cast<long>(input)) > 0 ? true : false;
1077  }
1078 
1083  template <typename T_Impl>
1084  inline bool BigIntegerBase<T_Impl>::operator> (const unsigned int input) const {
1085  return T_Impl::Compare(*this, static_cast<unsigned long>(input)) > 0 ? true : false;
1086  }
1087 
1092  template <typename T_Impl>
1093  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator>> (const unsigned long input) const {
1094  BigIntegerBase<T_Impl> output;
1095 
1096  T_Impl::RightShift(output, *this, input);
1097 
1098  return output;
1099  }
1100 
1105  template <typename T_Impl>
1107  T_Impl::RightShift(*this, *this, input);
1108  return *this;
1109  }
1110 
1115  template <typename T_Impl>
1116  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::operator<< (const unsigned long input) const {
1117  BigIntegerBase<T_Impl> output;
1118 
1119  T_Impl::LeftShift(output, *this, input);
1120 
1121  return output;
1122  }
1123 
1128  template <typename T_Impl>
1130  T_Impl::LeftShift(*this, *this, input);
1131  return *this;
1132  }
1133 
1137  template <typename T_Impl>
1139  BigIntegerBase<T_Impl> output;
1140 
1141  T_Impl::InvertBits(output, *this);
1142 
1143  return output;
1144  }
1145 
1150  template <typename T_Impl>
1152  BigIntegerBase<T_Impl> output;
1153 
1154  T_Impl::BitwiseAnd(output, *this, input);
1155 
1156  return output;
1157  }
1158 
1163  template <typename T_Impl>
1165  T_Impl::BitwiseAnd(*this, *this, input);
1166  return *this;
1167  }
1168 
1173  template <typename T_Impl>
1175  BigIntegerBase<T_Impl> output;
1176 
1177  T_Impl::BitwiseOr(output, *this, input);
1178 
1179  return output;
1180  }
1181 
1186  template <typename T_Impl>
1188  T_Impl::BitwiseOr(*this, *this, input);
1189  return *this;
1190  }
1191 
1196  template <typename T_Impl>
1198  BigIntegerBase<T_Impl> output;
1199 
1200  T_Impl::BitwiseXor(output, *this, input);
1201 
1202  return output;
1203  }
1204 
1209  template <typename T_Impl>
1211  T_Impl::BitwiseXor(*this, *this, input);
1212  return *this;
1213  }
1214 
1215  /* /Operator overloading */
1216 
1217 
1218  /* Utility methods */
1219 
1223  template <typename T_Impl>
1225  BigIntegerBase<T_Impl> output;
1226 
1227  T_Impl::GetNextPrime(output, *this);
1228 
1229  return output;
1230  }
1231 
1235  template <typename T_Impl>
1236  inline bool BigIntegerBase<T_Impl>::IsPrime () const {
1237  return T_Impl::IsPrime(*this);
1238  }
1239 
1244  template <typename T_Impl>
1246  T_Impl::SetBit(*this, index);
1247  return *this;
1248  }
1249 
1254  template <typename T_Impl>
1255  inline int BigIntegerBase<T_Impl>::GetBit (const size_t index) const {
1256  return T_Impl::GetBit(*this, index);
1257  }
1258 
1265  template <typename T_Impl>
1266  inline size_t BigIntegerBase<T_Impl>::GetSize (const unsigned int base) const {
1267  return T_Impl::GetSize(*this, base);
1268  }
1269 
1273  template <typename T_Impl>
1275  T_Impl::Abs(*this, *this);
1276  return *this;
1277  }
1278 
1282  template <typename T_Impl>
1284  BigIntegerBase<T_Impl> output;
1285 
1286  T_Impl::Abs(output, *this);
1287 
1288  return output;
1289  }
1290 
1295  template <typename T_Impl>
1297  T_Impl::Pow(*this, *this, power);
1298  return *this;
1299  }
1300 
1305  template <typename T_Impl>
1307  T_Impl::Pow(*this, *this, power);
1308  return *this;
1309  }
1310 
1315  template <typename T_Impl>
1316  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::Pow (const unsigned long power) {
1317  T_Impl::Pow(*this, *this, power);
1318  return *this;
1319  }
1320 
1325  template <typename T_Impl>
1327  T_Impl::Pow(*this, *this, static_cast<long>(power));
1328  return *this;
1329  }
1330 
1335  template <typename T_Impl>
1336  inline BigIntegerBase<T_Impl> &BigIntegerBase<T_Impl>::Pow (const unsigned int power) {
1337  T_Impl::Pow(*this, *this, static_cast<unsigned long>(power));
1338  return *this;
1339  }
1340 
1345  template <typename T_Impl>
1347  BigIntegerBase<T_Impl> output;
1348 
1349  T_Impl::Pow(output, *this, power);
1350 
1351  return output;
1352  }
1353 
1358  template <typename T_Impl>
1359  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::GetPow (const long power) const {
1360  BigIntegerBase<T_Impl> output;
1361 
1362  T_Impl::Pow(output, *this, power);
1363 
1364  return output;
1365  }
1366 
1371  template <typename T_Impl>
1372  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::GetPow (const unsigned long power) const {
1373  BigIntegerBase<T_Impl> output;
1374 
1375  T_Impl::Pow(output, *this, power);
1376 
1377  return output;
1378  }
1379 
1384  template <typename T_Impl>
1386  BigIntegerBase<T_Impl> output;
1387 
1388  T_Impl::Pow(output, *this, static_cast<long>(power));
1389 
1390  return output;
1391  }
1392 
1397  template <typename T_Impl>
1398  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::GetPow (const unsigned int power) const {
1399  BigIntegerBase<T_Impl> output;
1400 
1401  T_Impl::Pow(output, *this, static_cast<unsigned long>(power));
1402 
1403  return output;
1404  }
1405 
1411  template <typename T_Impl>
1413  T_Impl::PowModN(*this, *this, power, n);
1414  return *this;
1415  }
1416 
1422  template <typename T_Impl>
1424  T_Impl::PowModN(*this, *this, power, n);
1425  return *this;
1426  }
1427 
1433  template <typename T_Impl>
1435  T_Impl::PowModN(*this, *this, power, n);
1436  return *this;
1437  }
1438 
1444  template <typename T_Impl>
1446  T_Impl::PowModN(*this, *this, static_cast<long>(power), n);
1447  return *this;
1448  }
1449 
1455  template <typename T_Impl>
1457  T_Impl::PowModN(*this, *this, static_cast<unsigned long>(power), n);
1458  return *this;
1459  }
1460 
1466  template <typename T_Impl>
1468  BigIntegerBase<T_Impl> output;
1469 
1470  T_Impl::PowModN(output, *this, power, n);
1471 
1472  return output;
1473  }
1474 
1480  template <typename T_Impl>
1482  BigIntegerBase<T_Impl> output;
1483 
1484  T_Impl::PowModN(output, *this, power, n);
1485 
1486  return output;
1487  }
1488 
1494  template <typename T_Impl>
1495  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::GetPowModN (const unsigned long power, const BigIntegerBase<T_Impl> &n) const {
1496  BigIntegerBase<T_Impl> output;
1497 
1498  T_Impl::PowModN(output, *this, power, n);
1499 
1500  return output;
1501  }
1502 
1508  template <typename T_Impl>
1510  BigIntegerBase<T_Impl> output;
1511 
1512  T_Impl::PowModN(output, *this, static_cast<long>(power), n);
1513 
1514  return output;
1515  }
1516 
1522  template <typename T_Impl>
1523  inline BigIntegerBase<T_Impl> BigIntegerBase<T_Impl>::GetPowModN (const unsigned int power, const BigIntegerBase<T_Impl> &n) const {
1524  BigIntegerBase<T_Impl> output;
1525 
1526  T_Impl::PowModN(output, *this, static_cast<unsigned long>(power), n);
1527 
1528  return output;
1529  }
1530 
1535  template <typename T_Impl>
1537  T_Impl::InvertModN(*this, *this, n);
1538  return *this;
1539  }
1540 
1545  template <typename T_Impl>
1547  BigIntegerBase<T_Impl> output;
1548 
1549  T_Impl::InvertModN(output, *this, n);
1550 
1551  return output;
1552  }
1553 
1554  /* /Utility methods */
1555 
1556  /* Static utility methods */
1557 
1562  template <typename T_Impl>
1564  T_Impl::Swap(lhs, rhs);
1565  }
1566 
1572  template <typename T_Impl>
1574  BigIntegerBase<T_Impl> output;
1575 
1576  T_Impl::Gcd(output, lhs, rhs);
1577 
1578  return output;
1579  }
1580 
1586  template <typename T_Impl>
1588  BigIntegerBase<T_Impl> output;
1589 
1590  T_Impl::Lcm(output, lhs, rhs);
1591 
1592  return output;
1593  }
1594 
1595  /* /Static utility methods */
1596 
1597  /* Conversion methods */
1598 
1603  template <typename T_Impl>
1604  std::string BigIntegerBase<T_Impl>::ToString (const unsigned int base) const {
1605  return T_Impl::ToString(*this, base);
1606  }
1607 
1611  template <typename T_Impl>
1613  return T_Impl::ToUnsignedLong(*this);
1614  }
1615 
1616  /* /Conversion methods */
1617 
1618  /* Binary non-member operators */
1619 
1625  template <typename T_Impl>
1627  return rhs + lhs;
1628  }
1629 
1635  template <typename T_Impl>
1636  BigIntegerBase<T_Impl> operator+ (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1637  return rhs + lhs;
1638  }
1639 
1645  template <typename T_Impl>
1647  return rhs + lhs;
1648  }
1649 
1655  template <typename T_Impl>
1656  BigIntegerBase<T_Impl> operator+ (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1657  return rhs + lhs;
1658  }
1659 
1665  template <typename T_Impl>
1667  BigIntegerBase<T_Impl> output;
1668 
1669  T_Impl::Subtract(output, BigIntegerBase<T_Impl>(lhs), rhs);
1670 
1671  return output;
1672  }
1673 
1679  template <typename T_Impl>
1680  BigIntegerBase<T_Impl> operator- (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1681  BigIntegerBase<T_Impl> output;
1682 
1683  T_Impl::Subtract(output, BigIntegerBase<T_Impl>(lhs), rhs);
1684 
1685  return output;
1686  }
1687 
1693  template <typename T_Impl>
1695  BigIntegerBase<T_Impl> output;
1696 
1697  T_Impl::Subtract(output, BigIntegerBase<T_Impl>(lhs), rhs);
1698 
1699  return output;
1700  }
1701 
1707  template <typename T_Impl>
1708  BigIntegerBase<T_Impl> operator- (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1709  BigIntegerBase<T_Impl> output;
1710 
1711  T_Impl::Subtract(output, BigIntegerBase<T_Impl>(lhs), rhs);
1712 
1713  return output;
1714  }
1715 
1721  template <typename T_Impl>
1723  return rhs * lhs;
1724  }
1725 
1731  template <typename T_Impl>
1732  BigIntegerBase<T_Impl> operator* (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1733  return rhs * lhs;
1734  }
1735 
1741  template <typename T_Impl>
1743  return rhs * lhs;
1744  }
1745 
1751  template <typename T_Impl>
1752  BigIntegerBase<T_Impl> operator* (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1753  return rhs * lhs;
1754  }
1755 
1761  template <typename T_Impl>
1763  BigIntegerBase<T_Impl> output;
1764 
1765  T_Impl::Divide(output, BigIntegerBase<T_Impl>(lhs), rhs);
1766 
1767  return output;
1768  }
1769 
1775  template <typename T_Impl>
1776  BigIntegerBase<T_Impl> operator/ (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1777  BigIntegerBase<T_Impl> output;
1778 
1779  T_Impl::Divide(output, BigIntegerBase<T_Impl>(lhs), rhs);
1780 
1781  return output;
1782  }
1783 
1789  template <typename T_Impl>
1791  BigIntegerBase<T_Impl> output;
1792 
1793  T_Impl::Divide(output, BigIntegerBase<T_Impl>(lhs), rhs);
1794 
1795  return output;
1796  }
1797 
1803  template <typename T_Impl>
1804  BigIntegerBase<T_Impl> operator/ (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1805  BigIntegerBase<T_Impl> output;
1806 
1807  T_Impl::Divide(output, BigIntegerBase<T_Impl>(lhs), rhs);
1808 
1809  return output;
1810  }
1811 
1817  template <typename T_Impl>
1819  BigIntegerBase<T_Impl> output;
1820 
1821  T_Impl::Modulo(output, BigIntegerBase<T_Impl>(lhs), rhs);
1822 
1823  return output;
1824  }
1825 
1831  template <typename T_Impl>
1832  BigIntegerBase<T_Impl> operator% (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1833  BigIntegerBase<T_Impl> output;
1834 
1835  T_Impl::Modulo(output, BigIntegerBase<T_Impl>(lhs), rhs);
1836 
1837  return output;
1838  }
1839 
1845  template <typename T_Impl>
1847  BigIntegerBase<T_Impl> output;
1848 
1849  T_Impl::Modulo(output, BigIntegerBase<T_Impl>(lhs), rhs);
1850 
1851  return output;
1852  }
1853 
1859  template <typename T_Impl>
1860  BigIntegerBase<T_Impl> operator% (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1861  BigIntegerBase<T_Impl> output;
1862 
1863  T_Impl::Modulo(output, BigIntegerBase<T_Impl>(lhs), rhs);
1864 
1865  return output;
1866  }
1867 
1873  template <typename T_Impl>
1874  bool operator== (const long lhs, const BigIntegerBase<T_Impl> &rhs) {
1875  return rhs == lhs;
1876  }
1877 
1883  template <typename T_Impl>
1884  bool operator== (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1885  return rhs == lhs;
1886  }
1887 
1893  template <typename T_Impl>
1894  bool operator== (const int lhs, const BigIntegerBase<T_Impl> &rhs) {
1895  return rhs == lhs;
1896  }
1897 
1903  template <typename T_Impl>
1904  bool operator== (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1905  return rhs == lhs;
1906  }
1907 
1913  template <typename T_Impl>
1914  bool operator!= (const long lhs, const BigIntegerBase<T_Impl> &rhs) {
1915  return rhs != lhs;
1916  }
1917 
1923  template <typename T_Impl>
1924  bool operator!= (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1925  return rhs != lhs;
1926  }
1927 
1933  template <typename T_Impl>
1934  bool operator!= (const int lhs, const BigIntegerBase<T_Impl> &rhs) {
1935  return rhs != lhs;
1936  }
1937 
1943  template <typename T_Impl>
1944  bool operator!= (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1945  return rhs != lhs;
1946  }
1947 
1953  template <typename T_Impl>
1954  bool operator< (const long lhs, const BigIntegerBase<T_Impl> &rhs) {
1955  return rhs > lhs;
1956  }
1957 
1963  template <typename T_Impl>
1964  bool operator< (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
1965  return rhs > lhs;
1966  }
1967 
1973  template <typename T_Impl>
1974  bool operator< (const int lhs, const BigIntegerBase<T_Impl> &rhs) {
1975  return rhs > lhs;
1976  }
1977 
1983  template <typename T_Impl>
1984  bool operator< (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
1985  return rhs > lhs;
1986  }
1987 
1993  template <typename T_Impl>
1994  bool operator<= (const long lhs, const BigIntegerBase<T_Impl> &rhs) {
1995  return rhs >= lhs;
1996  }
1997 
2003  template <typename T_Impl>
2004  bool operator<= (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
2005  return rhs >= lhs;
2006  }
2007 
2013  template <typename T_Impl>
2014  bool operator<= (const int lhs, const BigIntegerBase<T_Impl> &rhs) {
2015  return rhs >= lhs;
2016  }
2017 
2023  template <typename T_Impl>
2024  bool operator<= (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
2025  return rhs >= lhs;
2026  }
2027 
2033  template <typename T_Impl>
2034  bool operator>= (const long lhs, const BigIntegerBase<T_Impl> &rhs) {
2035  return rhs <= lhs;
2036  }
2037 
2043  template <typename T_Impl>
2044  bool operator>= (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
2045  return rhs <= lhs;
2046  }
2047 
2053  template <typename T_Impl>
2054  bool operator>= (const int lhs, const BigIntegerBase<T_Impl> &rhs) {
2055  return rhs <= lhs;
2056  }
2057 
2063  template <typename T_Impl>
2064  bool operator>= (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
2065  return rhs <= lhs;
2066  }
2067 
2073  template <typename T_Impl>
2074  bool operator> (const long lhs, const BigIntegerBase<T_Impl> &rhs) {
2075  return rhs < lhs;
2076  }
2077 
2083  template <typename T_Impl>
2084  bool operator> (const unsigned long lhs, const BigIntegerBase<T_Impl> &rhs) {
2085  return rhs < lhs;
2086  }
2087 
2093  template <typename T_Impl>
2094  bool operator> (const int lhs, const BigIntegerBase<T_Impl> &rhs) {
2095  return rhs < lhs;
2096  }
2097 
2103  template <typename T_Impl>
2104  bool operator> (const unsigned int lhs, const BigIntegerBase<T_Impl> &rhs) {
2105  return rhs < lhs;
2106  }
2107 
2108  /* /Binary non-member operators */
2109 
2110 }//namespace Core
2111 }//namespace SeComLib
2112 
2113 #endif//BIG_INTEGER_BASE_IMPLEMENTATION_GUARD
BigIntegerBase< T_Impl > & operator++()
Prefix increment unary operator.
BigIntegerBase< T_Impl > & operator--()
Prefix decrement unary operator.
bool operator>=(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase greater than or equal to binary operator.
BigIntegerBase< T_Impl > & SetBit(const size_t index)
Sets a bit in the current instance at the specified index.
bool operator<(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase less than binary operator.
BigIntegerBase< T_Impl > operator*(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long multiplication binary operator
int GetBit(const size_t index) const
Returns the bit specified by index.
BigIntegerBase< T_Impl > GetNextPrime() const
Computes the first prime greater than the current instance.
bool operator>(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase greater than binary operator.
BigIntegerBase< T_Impl > operator~() const
One's complement unary operator.
std::string ToString(const unsigned int base=2) const
Convert to std::string in the specified base.
BigIntegerBase< T_Impl > operator>>(const unsigned long input) const
Bitwise right shift binary operator.
BigIntegerBase< T_Impl > GetPowModN(const BigIntegerBase< T_Impl > &power, const BigIntegerBase< T_Impl > &n) const
Computes the integer raised to the specified BigIntegerBase power modulo n.
BigIntegerBase< T_Impl > & operator-=(const BigIntegerBase< T_Impl > &input)
BigIntegerBase subtraction & assignment binary operator.
BigIntegerBase< T_Impl > & operator|=(const BigIntegerBase< T_Impl > &input)
Bitwise inclusive OR & assignment binary operator.
bool operator==(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long equality binary operator
unsigned long ToUnsignedLong() const
Convert to unsigned long.
BigIntegerBase< T_Impl > & operator<<=(const unsigned long input)
Bitwise left shift & assignment binary operator.
BigIntegerBase< T_Impl > & operator&=(const BigIntegerBase< T_Impl > &input)
Bitwise AND & assignment binary operator.
BigIntegerBase< T_Impl > & operator>>=(const unsigned long input)
Bitwise right shift & assignment binary operator.
BigIntegerBase< T_Impl > operator&(const BigIntegerBase< T_Impl > &input) const
Bitwise AND binary operator.
bool operator>=(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long greater than or equal binary operator
BigIntegerBase< T_Impl > operator<<(const unsigned long input) const
Bitwise left shift binary operator.
BigIntegerBase< T_Impl > & Abs()
Sets the current instance to its absolute value.
BigIntegerBase< T_Impl > & operator/=(const BigIntegerBase< T_Impl > &input)
BigIntegerBase division & assignment binary operator.
bool IsPrime() const
Tests if the current instance is a prime number.
BigIntegerBase< T_Impl > operator/(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase division binary operator.
size_t GetSize(const unsigned int base=2) const
Gets the length of the integer in the specified base.
BigIntegerBase< T_Impl > operator%(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long modulus binary operator
BigIntegerBase< T_Impl > operator-() const
Unary negation operator.
BigIntegerBase()
Default constructor.
BigIntegerBase< T_Impl > operator+() const
Unary plus operator.
static BigIntegerBase< T_Impl > Gcd(const BigIntegerBase< T_Impl > &lhs, const BigIntegerBase< T_Impl > &rhs)
Computes the greatest common divisor of lhs and rhs.
BigIntegerBase< T_Impl > & Pow(const BigIntegerBase< T_Impl > &power)
Raises the current instance to the specified BigIntegerBase power.
BigIntegerBase< T_Impl > operator|(const BigIntegerBase< T_Impl > &input) const
Bitwise inclusive OR binary operator.
BigIntegerBase< T_Impl > operator^(const BigIntegerBase< T_Impl > &input) const
Bitwise exclusive OR binary operator.
bool operator==(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase equality binary operator.
BigIntegerBase< T_Impl > GetPow(const BigIntegerBase< T_Impl > &power) const
Computes the integer raised to the specified BigIntegerBase power.
BigIntegerBase< T_Impl > & operator^=(const BigIntegerBase< T_Impl > &input)
Bitwise exclusive OR & assignment binary operator.
bool operator!=(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long inequality binary operator
BigIntegerBase< T_Impl > & PowModN(const BigIntegerBase< T_Impl > &power, const BigIntegerBase< T_Impl > &n)
Raises the current instance to the specified BigIntegerBase power modulo n.
BigIntegerBase< T_Impl > & operator*=(const BigIntegerBase< T_Impl > &input)
BigIntegerBase multiplication & assignment binary operator.
BigIntegerBase< T_Impl > & operator+=(const BigIntegerBase< T_Impl > &input)
BigIntegerBase addition & assignment binary operator.
BigIntegerBase< T_Impl > & operator=(const BigIntegerBase< T_Impl > &input)
BigIntegerBase assignment operator.
BigIntegerBase< T_Impl > GetAbs() const
Computes the absolute value of the current instance.
Template class which adds syntactic sugar to big integer operations.
BigIntegerBase< T_Impl > operator+(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long addition binary operator
bool operator<=(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase less than or equal to binary operator.
static void Swap(BigIntegerBase< T_Impl > &lhs, BigIntegerBase< T_Impl > &rhs)
Swaps lhs with rhs efficiently.
BigIntegerBase< T_Impl > operator*(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase multiplication binary operator.
BigIntegerBase< T_Impl > operator-(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long subtraction binary operator
BigIntegerBase< T_Impl > GetInverseModN(const BigIntegerBase< T_Impl > &n) const
Computes the inverse modulo n.
BigIntegerBase< T_Impl > & operator%=(const BigIntegerBase< T_Impl > &input)
BigIntegerBase modulus & assignment binary operator.
bool operator!=(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase inequality binary operator.
BigIntegerBase< T_Impl > & InvertModN(const BigIntegerBase< T_Impl > &n)
Inverts the current instance modulo n.
static BigIntegerBase< T_Impl > Lcm(const BigIntegerBase< T_Impl > &lhs, const BigIntegerBase< T_Impl > &rhs)
Computes the least common multiple of lhs and rhs.
BigIntegerBase< T_Impl > operator/(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long division binary operator
bool operator>(const long lhs, const BigIntegerBase< T_Impl > &rhs)
long greater than binary operator
BigIntegerBase< T_Impl > operator%(const BigIntegerBase< T_Impl > &input) const
BigIntegerBase modulus binary operator.