ffead.server.doc
Bigint.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * Bigint.h
18  *
19  * Created on: 04-Mar-2013
20  * Author: sumeetc
21  */
22 
23 #ifndef BIGINT_H_
24 #define BIGINT_H_
25 #include "string"
26 #include "vector"
27 #include "algorithm"
28 #include "CastUtil.h"
29 #include <iostream>
30 using namespace std;
31 
32 
33 class Bigint {
34  friend class Bigdecimal;
35  vector<int> parts;
36  bool isPositive;
37  int decimalStartsAt;
38  void create(string value);
39  void checkAndSetIfZero();
40  int decompose(string fnvalue, string snvalue, Bigint number, int recurse, string& build, bool isDecimal,int);
41  void internalAdd(Bigint number);
42  void internalDivide(Bigint number, bool isDecimal,int);
43 public:
44  static string BLANK;
45  static string MINUS;
46  static string ZERO;
47  static int ZERO_INT;
48  static int NUM_LENGTH;
49  static int NUM_MAX;
50  static int NUM_MAX_THRESHOLD;
51  Bigint();
52  Bigint(string value);
53  void add(Bigint number);
54  Bigint operator+(Bigint number);
55  Bigint operator-(Bigint number);
56  Bigint operator*(Bigint number);
57  Bigint operator/(Bigint number);
58  Bigint& operator++();
59  Bigint& operator+=(Bigint number);
60  Bigint& operator--();
61  Bigint& operator-=(Bigint number);
62  friend bool operator== (Bigint &lhs, Bigint &rhs);
63  friend bool operator!= (Bigint &lhs, Bigint &rhs);
64  friend bool operator< (Bigint &lhs, Bigint &rhs);
65  friend bool operator<= (Bigint &lhs, Bigint &rhs);
66  friend bool operator> (Bigint &lhs, Bigint &rhs);
67  friend bool operator>= (Bigint &lhs, Bigint &rhs);
68  void subtract(Bigint number);
69  void multiply(Bigint number);
70  void divide(Bigint number);
71  static int compare(Bigint number1, Bigint number2);
72  int compare(Bigint number);
73  string toString();
74  virtual ~Bigint();
75 };
76 
77 #endif /* BIGINT_H_ */