本文整理汇总了C++中BigInteger::getNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ BigInteger::getNumber方法的具体用法?C++ BigInteger::getNumber怎么用?C++ BigInteger::getNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInteger
的用法示例。
在下文中一共展示了BigInteger::getNumber方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add
//-------------------------------------------------------------
BigInteger BigInteger::operator + (BigInteger b)
{
BigInteger addition;
if( getSign() == b.getSign() ) // both +ve or -ve
{
addition.setNumber( add(getNumber(), b.getNumber() ) );
addition.setSign( getSign() );
}
else // sign different
{
if( absolute() > b.absolute() )
{
addition.setNumber( subtract(getNumber(), b.getNumber() ) );
addition.setSign( getSign() );
}
else
{
addition.setNumber( subtract(b.getNumber(), getNumber() ) );
addition.setSign( b.getSign() );
}
}
if(addition.getNumber() == "0") // avoid (-0) problem
addition.setSign(false);
return addition;
}
示例2: multiply
BigInteger BigInteger::operator * (BigInteger b) {
BigInteger mul;
mul.setNumber( multiply(getNumber(), b.getNumber() ) );
mul.setSign( getSign() != b.getSign() );
if(mul.getNumber() == "0") // avoid (-0) problem
mul.setSign(false);
return mul;
}
示例3: toInt
// Warning: Denomerator must be within "long long" size not "BigInteger"
BigInteger BigInteger::operator / (BigInteger b) {
long long den = toInt( b.getNumber() );
BigInteger div;
div.setNumber( divide(getNumber(), den).first );
div.setSign( getSign() != b.getSign() );
if(div.getNumber() == "0") // avoid (-0) problem
div.setSign(false);
return div;
}
示例4:
//-------------------------------------------------------------
void BigInteger::operator = (BigInteger b)
{
setNumber( b.getNumber() );
setSign( b.getSign() );
}
示例5: less
//-------------------------------------------------------------
bool BigInteger::less(BigInteger n1, BigInteger n2)
{
bool sign1 = n1.getSign();
bool sign2 = n2.getSign();
if(sign1 && ! sign2) // if n1 is -ve and n2 is +ve
return true;
else if(! sign1 && sign2)
return false;
else if(! sign1) // both +ve
{
if(n1.getNumber().length() < n2.getNumber().length() )
return true;
if(n1.getNumber().length() > n2.getNumber().length() )
return false;
return n1.getNumber() < n2.getNumber();
}
else // both -ve
{
if(n1.getNumber().length() > n2.getNumber().length())
return true;
if(n1.getNumber().length() < n2.getNumber().length())
return false;
return n1.getNumber().compare( n2.getNumber() ) > 0; // greater with -ve sign is LESS
}
}
示例6: equals
bool BigInteger::equals(BigInteger n1, BigInteger n2)
{
return n1.getNumber() == n2.getNumber()
&& n1.getSign() == n2.getSign();
}