1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-02-22 14:00:13 +00:00

conversion from ld to bignum

This commit is contained in:
Zeno Rogue 2019-12-25 11:51:56 +01:00
parent 454024a42c
commit 35f076a171

View File

@ -300,6 +300,7 @@ struct bignum {
bignum& operator +=(const bignum& b);
void addmul(const bignum& b, int factor);
string get_str(int max_length) const;
bignum(ld d);
bool operator < (const bignum&) const;
@ -472,4 +473,13 @@ string bignum::get_str(int max_length) const {
return ret;
}
bignum::bignum(ld d) {
if(d == 0) return;
int n = 1;
while(d > BASE) d /= BASE, n++;
digits.resize(n);
n--;
while(n >= 0) { digits[n] = int(d); d -= digits[n]; d *= BASE; n--; }
}
}