Merge branch 'phoenix' of https://github.com/InvictusInnovations/fc into phoenix

This commit is contained in:
vogel76 2014-06-03 15:57:05 +02:00
commit 3e4f4b0d4c
3 changed files with 25 additions and 6 deletions

View file

@ -11,7 +11,7 @@ namespace fc {
public: public:
bigint( const std::vector<char>& bige ); bigint( const std::vector<char>& bige );
bigint( const char* bige, uint32_t l ); bigint( const char* bige, uint32_t l );
bigint( unsigned long i ); bigint(uint64_t value);
bigint( ); bigint( );
bigint( const bigint& c ); bigint( const bigint& c );
bigint( bigint&& c ); bigint( bigint&& c );

View file

@ -49,7 +49,7 @@ namespace fc {
friend class tcp_server; friend class tcp_server;
class impl; class impl;
#ifdef _WIN64 #ifdef _WIN64
fc::fwd<impl,0x70> my; fc::fwd<impl,0x78> my;
#else #else
fc::fwd<impl,0x4c> my; fc::fwd<impl,0x4c> my;
#endif #endif

View file

@ -6,6 +6,16 @@
#include <fc/exception/exception.hpp> #include <fc/exception/exception.hpp>
#ifdef _MSC_VER
# include <stdlib.h>
# define bswap_64(x) _byteswap_uint64(x)
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define bswap_64(x) OSSwapInt64(x)
#else
# include <byteswap.h>
#endif
namespace fc { namespace fc {
bigint::bigint( const char* bige, uint32_t l ) { bigint::bigint( const char* bige, uint32_t l ) {
n = BN_bin2bn( (const unsigned char*)bige, l, NULL ); n = BN_bin2bn( (const unsigned char*)bige, l, NULL );
@ -28,9 +38,10 @@ namespace fc {
return BN_dup( n ); return BN_dup( n );
} }
bigint::bigint( unsigned long i ) bigint::bigint(uint64_t value)
:n(BN_new()) { {
BN_set_word( n, i ); uint64_t big_endian_value = bswap_64(value);
n = BN_bin2bn((const unsigned char*)&big_endian_value, sizeof(big_endian_value), NULL);
} }
bigint::bigint( const bigint& c ) { bigint::bigint( const bigint& c ) {
@ -47,7 +58,15 @@ namespace fc {
} }
bool bigint::is_negative()const { return BN_is_negative(n); } bool bigint::is_negative()const { return BN_is_negative(n); }
int64_t bigint::to_int64()const { return BN_get_word(n); }
int64_t bigint::to_int64() const
{
FC_ASSERT(BN_num_bits(n) <= 63);
size_t size = BN_num_bytes(n);
uint64_t abs_value = 0;
BN_bn2bin(n, (unsigned char*)&abs_value + (sizeof(uint64_t) - size));
return BN_is_negative(n) ? -(int64_t)bswap_64(abs_value) : bswap_64(abs_value);
}
int64_t bigint::log2()const { return BN_num_bits(n); } int64_t bigint::log2()const { return BN_num_bits(n); }
bool bigint::operator < ( const bigint& c )const { bool bigint::operator < ( const bigint& c )const {