1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Fix converting int to int256 (#925)

Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
EmelyanenkoK 2024-03-04 17:37:42 +03:00 committed by GitHub
parent 310dd6dec1
commit b09f910bf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 15 deletions

View file

@ -169,8 +169,6 @@ class PropagateConstSpan {
size_t size_{0};
};
struct Normalize {};
template <class Tr = BigIntInfo>
class AnyIntView {
public:
@ -290,6 +288,7 @@ class BigIntG {
public:
enum { word_bits = Tr::word_bits, word_shift = Tr::word_shift, max_bits = len, word_cnt = len / word_shift + 1 };
typedef typename Tr::word_t word_t;
typedef typename Tr::uword_t uword_t;
typedef Tr Traits;
typedef BigIntG<len * 2, Tr> DoubleInt;
@ -312,9 +311,6 @@ class BigIntG {
BigIntG() : n(0) {
}
explicit BigIntG(word_t x) : n(1) {
digits[0] = x;
}
BigIntG(Normalize, word_t x) : n(1) {
if (x >= -Tr::Half && x < Tr::Half) {
digits[0] = x;
} else if (len <= 1) {
@ -325,6 +321,25 @@ class BigIntG {
digits[n++] = (x >> Tr::word_shift) + (digits[0] < 0);
}
}
explicit BigIntG(uword_t x) : n(1) {
if (x < (uword_t)Tr::Half) {
digits[0] = x;
} else if (len <= 1) {
digits[0] = x;
normalize_bool();
} else {
digits[0] = ((x ^ Tr::Half) & (Tr::Base - 1)) - Tr::Half;
digits[n++] = (x >> Tr::word_shift) + (digits[0] < 0);
}
}
explicit BigIntG(unsigned x) : BigIntG(uword_t(x)) {
}
explicit BigIntG(int x) : BigIntG(word_t(x)) {
}
explicit BigIntG(unsigned long x) : BigIntG(uword_t(x)) {
}
explicit BigIntG(long x) : BigIntG(word_t(x)) {
}
BigIntG(const BigIntG& x) : n(x.n) {
std::memcpy(digits, x.digits, n * sizeof(word_t));
///std::cout << "(BiCC " << (const void*)&x << "->" << (void*)this << ")";
@ -2556,7 +2571,7 @@ typedef BigIntG<257, BigIntInfo> BigInt256;
template <int n = 257>
BigIntG<n, BigIntInfo> make_bigint(long long x) {
return BigIntG<n, BigIntInfo>{Normalize(), x};
return BigIntG<n, BigIntInfo>{x};
}
namespace literals {