本文整理汇总了C++中BigNumber::addSymbolInfront方法的典型用法代码示例。如果您正苦于以下问题:C++ BigNumber::addSymbolInfront方法的具体用法?C++ BigNumber::addSymbolInfront怎么用?C++ BigNumber::addSymbolInfront使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigNumber
的用法示例。
在下文中一共展示了BigNumber::addSymbolInfront方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addPositiveBigNumber
// ARITHMETICS
BigNumber BigNumber::addPositiveBigNumber(BigNumber b)
{
BigNumber minBN;
BigNumber maxBN;
BigNumber result;
if(*this > b)
{
minBN = b;
maxBN = *this;
}
else
{
minBN = *this;
maxBN = b;
}
minBN.addZerosInfront(maxBN.length() - minBN.length());
/*
1 + 1 = 2 : plusOne = 0;
5 + 5 = 0 : plusOne = 1;
*/
int plusOne = 0;
int i = 0;
while(i < maxBN.length())
{
int temp = plusOne + maxBN[maxBN.length() - 1 - i] + minBN[minBN.length() - 1 - i];
if(temp > 9)
{
temp %= 10;
plusOne = 1;
}
else
plusOne = 0;
result.addSymbolInfront(intToString(temp));
i++;
}
if(plusOne == 1)
result.addSymbolInfront("1");
result.removeFrontZeroes();
return result;
}
示例2: subsractPositiveBigNumber
BigNumber BigNumber::subsractPositiveBigNumber(BigNumber b)
{
BigNumber minBN;
BigNumber maxBN;
BigNumber result;
bool isNegative;
if(*this >= b)
{
minBN = b;
maxBN = *this;
isNegative = false;
}
else
{
minBN = *this;
maxBN = b;
isNegative = true;
}
minBN.addZerosInfront(maxBN.length() - minBN.length());
int minusOne = 0; // SIMILAR TO PLUSONE
int i = 0;
while(i < maxBN.length())
{
int temp = 10 + maxBN[maxBN.length()- 1 - i] - minusOne - minBN[minBN.length()- 1 - i];
if(temp > 9)
minusOne = 0;
else
minusOne = 1;
temp %= 10;
result.addSymbolInfront(intToString(temp));
i++;
}
result.removeFrontZeroes();
if(isNegative)
result.addSymbolInfront("-");
return result;
}