高精度减法
bigNum bigSub(bigNum* a, bigNum* b)
{
bigNum c;
for (int i = 0; i < a->len || i < b->len; i++)
{
if (a->num[i] < b->num[i])
{
a->num[i] += 10;
a->num[i + 1] -= 1;
}
c.num[i] = a->num[i] - b->num[i];
}
while (c.num[c.len - 1] == 0&&c.len>=1)
c.len--;
return c;
}
注意:只能实现结果为正,故使用前需用比较
混合加法
bigNum smallMul(bigNum* a, int b)
{
int carry = 0; int len = a->len;
bigNum c;
for (int i = 0; i < len; i++)
{
int temp = b * a->num[i] + carry;
c.num[c.len++] = temp % 10;
carry = temp / 10;
}
while (carry != 0)
{
c.num[c.len++] = carry % 10;
carry = carry / 10;
}
return c;
}
标签:10,bigNum,高精度,int,len,num,加法,carry,减法
From: https://www.cnblogs.com/Arc-ux/p/18365276