BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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 
fc::bigint::operator*=
bigint operator*=(const bigint &a)
Definition: bigint.cpp:154
fc::bigint::operator>=
bool operator>=(const bigint &c) const
Definition: bigint.cpp:71
fc::bigint::operator/=
bigint operator/=(const bigint &a)
Definition: bigint.cpp:146
fc::bigint::operator>
bool operator>(const bigint &c) const
Definition: bigint.cpp:68
fc
Definition: api.hpp:15
fc::bigint::operator+
bigint operator+(const bigint &a) const
Definition: bigint.cpp:105
fc::bigint::operator<
bool operator<(const bigint &c) const
Definition: bigint.cpp:65
fc::bigint::operator=
bigint & operator=(const bigint &a)
Definition: bigint.cpp:198
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::bigint::bigint
bigint()
Definition: bigint.cpp:23
fc::bigint::operator++
bigint & operator++()
Definition: bigint.cpp:90
fc::bigint
Definition: bigint.hpp:10
fc::bigint::operator*
bigint operator*(const bigint &a) const
Definition: bigint.cpp:124
fc::bigint::dup
BIGNUM * dup() const
Definition: bigint.cpp:27
fc::bigint::operator/
bigint operator/(const bigint &a) const
Definition: bigint.cpp:131
fc::bigint::exp
bigint exp(const bigint &c) const
Definition: bigint.cpp:182
fc::bigint::is_negative
bool is_negative() const
Definition: bigint.cpp:52
fc::bigint::operator-
bigint operator-(const bigint &a) const
Definition: bigint.cpp:177
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::bigint::operator>>=
bigint & operator>>=(uint32_t i)
Definition: bigint.cpp:159
fc::bigint::operator<<=
bigint & operator<<=(uint32_t i)
Definition: bigint.cpp:167
fc::bigint::operator-=
bigint & operator-=(const bigint &a)
Definition: bigint.cpp:116
fc::bigint::operator--
bigint & operator--()
Definition: bigint.cpp:100
fc::bigint::to_int64
int64_t to_int64() const
Definition: bigint.cpp:54
fc::bigint::~bigint
~bigint()
Definition: bigint.cpp:48
fc::bigint::operator!=
bool operator!=(const bigint &c) const
Definition: bigint.cpp:77
fc::bigint::operator==
bool operator==(const bigint &c) const
Definition: bigint.cpp:74
fc::bigint::operator+=
bigint & operator+=(const bigint &a)
Definition: bigint.cpp:110
fc::bigint::log2
int64_t log2() const
Definition: bigint.cpp:64
fc::bigint::operator%
bigint operator%(const bigint &a) const
Definition: bigint.cpp:138
fc::bigint::random
static bigint random(uint32_t bits, int t, int)
fc::bigint::get
BIGNUM * get() const
Definition: bigint.hpp:65
BIGNUM
bignum_st BIGNUM
Definition: bigint.hpp:6