BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
bigint.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <stdint.h>
3 #include <string>
4 #include <vector>
5 
6 struct bignum_st;
7 typedef bignum_st BIGNUM;
8 
9 namespace fc {
10  class bigint {
11  public:
12  bigint( const std::vector<char>& bige );
13  bigint( const char* bige, uint32_t l );
14  bigint(uint64_t value);
15  bigint( );
16  bigint( const bigint& c );
17  bigint( bigint&& c );
18  explicit bigint( BIGNUM* n );
19  ~bigint();
20 
21  bigint& operator = ( const bigint& a );
22  bigint& operator = ( bigint&& a );
23 
24  explicit operator bool()const;
25 
26  bool is_negative()const;
27  int64_t to_int64()const;
28 
29  int64_t log2()const;
30  bigint exp( const bigint& c )const;
31 
32  static bigint random( uint32_t bits, int t, int );
33 
34  bool operator < ( const bigint& c )const;
35  bool operator > ( const bigint& c )const;
36  bool operator >= ( const bigint& c )const;
37  bool operator == ( const bigint& c )const;
38  bool operator != ( const bigint& c )const;
39 
40  bigint operator + ( const bigint& a )const;
41  bigint operator * ( const bigint& a )const;
42  bigint operator / ( const bigint& a )const;
43  bigint operator % ( const bigint& a )const;
44  bigint operator /= ( const bigint& a );
45  bigint operator *= ( const bigint& a );
46  bigint& operator += ( const bigint& a );
47  bigint& operator -= ( const bigint& a );
48  bigint& operator <<= ( uint32_t i );
49  bigint& operator >>= ( uint32_t i );
50  bigint operator - ( const bigint& a )const;
51 
52 
53  bigint operator++(int);
54  bigint& operator++();
55  bigint operator--(int);
56  bigint& operator--();
57 
58  operator std::string()const;
59 
60  // returns bignum as bigendian bytes
61  operator std::vector<char>()const;
62 
63  BIGNUM* dup()const;
64 
65  BIGNUM* get()const { return n; }
66  private:
67  BIGNUM* n;
68  };
69 
70  class variant;
72  void to_variant( const bigint& bi, variant& v, uint32_t max_depth = 1 );
74  void from_variant( const variant& v, bigint& bi, uint32_t max_depth = 1 );
75 } // namespace fc
76 
bool is_negative() const
Definition: bigint.cpp:52
bigint operator-(const bigint &a) const
Definition: bigint.cpp:177
bigint exp(const bigint &c) const
Definition: bigint.cpp:182
bool operator<(const bigint &c) const
Definition: bigint.cpp:65
bigint operator*=(const bigint &a)
Definition: bigint.cpp:154
bool operator==(const bigint &c) const
Definition: bigint.cpp:74
bigint operator+(const bigint &a) const
Definition: bigint.cpp:105
bigint operator%(const bigint &a) const
Definition: bigint.cpp:138
int64_t log2() const
Definition: bigint.cpp:64
bigint operator*(const bigint &a) const
Definition: bigint.cpp:124
bigint & operator=(const bigint &a)
Definition: bigint.cpp:198
bigint & operator++()
Definition: bigint.cpp:90
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
bigint & operator<<=(uint32_t i)
Definition: bigint.cpp:167
BIGNUM * dup() const
Definition: bigint.cpp:27
bool operator>=(const bigint &c) const
Definition: bigint.cpp:71
bigint & operator-=(const bigint &a)
Definition: bigint.cpp:116
bool operator!=(const bigint &c) const
Definition: bigint.cpp:77
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
int64_t to_int64() const
Definition: bigint.cpp:54
bigint operator/=(const bigint &a)
Definition: bigint.cpp:146
bool operator>(const bigint &c) const
Definition: bigint.cpp:68
bigint & operator+=(const bigint &a)
Definition: bigint.cpp:110
bigint & operator>>=(uint32_t i)
Definition: bigint.cpp:159
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
bignum_st BIGNUM
Definition: bigint.hpp:6
static bigint random(uint32_t bits, int t, int)
bigint & operator--()
Definition: bigint.cpp:100
Definition: api.hpp:15
bigint operator/(const bigint &a) const
Definition: bigint.cpp:131