mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-05-19 23:54:08 +00:00
conversion from ld to bignum
This commit is contained in:
parent
454024a42c
commit
35f076a171
10
util.cpp
10
util.cpp
@ -300,6 +300,7 @@ struct bignum {
|
|||||||
bignum& operator +=(const bignum& b);
|
bignum& operator +=(const bignum& b);
|
||||||
void addmul(const bignum& b, int factor);
|
void addmul(const bignum& b, int factor);
|
||||||
string get_str(int max_length) const;
|
string get_str(int max_length) const;
|
||||||
|
bignum(ld d);
|
||||||
|
|
||||||
bool operator < (const bignum&) const;
|
bool operator < (const bignum&) const;
|
||||||
|
|
||||||
@ -472,4 +473,13 @@ string bignum::get_str(int max_length) const {
|
|||||||
return ret;
|
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--; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user