I'm currently facing a problem but I don't know why it wrong?
// ll ís long long
ll cnt = 24822089714520516;
cout << "xpow: " << xpow(10LL, 16) << endl;
cout << "cnt: " << cnt << endl;
ll a = xpow(10LL, 16) + cnt - 1;
ll b = round(xpow(10LL, 16)) + cnt - 1;
cout << "cur_num (without round): " << a << endl;
cout << "cur_num (with round): " << b << endl;
with xpow
is defined by myself:
ll xpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans *= a;
b >>= 1;
if (b)
a *= a;
};
return ans;
};
When I run my code, I get this log:
xpow: 10000000000000000
cnt: 24822089714520516
cur_num (without round): 34822089714520515
cur_num (with round): 34822089714520516
As you see, my result if I use round is differenced with one when I don't round (smaller than 1 unit)
It may be my computer's problem, but may be no. Can anyone explain why?
Thanks so much!