当前位置: 首页>>代码示例>>C++>>正文


C++ BigInteger::Cardinality方法代码示例

本文整理汇总了C++中BigInteger::Cardinality方法的典型用法代码示例。如果您正苦于以下问题:C++ BigInteger::Cardinality方法的具体用法?C++ BigInteger::Cardinality怎么用?C++ BigInteger::Cardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BigInteger的用法示例。


在下文中一共展示了BigInteger::Cardinality方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CompareTo

int BigInteger::CompareTo(const BigInteger& a) const
{
    if (m_sign && !a.m_sign)
        return 1;
    if (!m_sign && a.m_sign)
        return -1;

    int order = 0;
    if (Cardinality() < a.Cardinality())
    {
        order = -1;
    }
    else if (Cardinality() > a.Cardinality())
    {
        order = 1;
    }
    else
    {
        for (int i = Cardinality() - 1; i >= 0; i--)
        {
            if (m_digits[i] < a.m_digits[i])
            {
                order = -1;
                break;
            }
            else if (m_digits[i] > a.m_digits[i])
            {
                order = 1;
                break;
            }
        }
    }

    return (m_sign) ? order : -order;
}
开发者ID:peterloos,项目名称:Cpp_BigInteger,代码行数:35,代码来源:BigInteger.cpp

示例2: tmp

BigInteger operator/ (const BigInteger& a, const BigInteger& b)
{
    BigInteger remainder;

    char* result = new char[1];
    result[0] = '\0';

    // need positive divisor
    BigInteger bAbs = b.Abs();

    int pos = a.Cardinality() - 1;
    while (pos >= 0)
    {
        // append next digit from dividend to temporary divisor
        int len = (remainder.IsNull()) ? 1 : remainder.Cardinality() + 1;
        int* digits = new int[len];

        // copy old digits
        for (int k = 0; k < len - 1; k++)
            digits[k + 1] = remainder.m_digits[k];

        // fetch digit from dividend
        digits[0] = a.m_digits[pos];

        remainder = BigInteger(true, digits, len);  // TODO: Ob len hier stimmt, ist OFFEN

        // divide current dividend with divisor
        int n = 0;
        while (bAbs <= remainder)
        {
            n++;
            remainder -= bAbs;
        }

        // append digit to result string
        int slen = strlen(result);
        char* tmp = new char[slen + 2];
        strcpy_s (tmp, slen + 2, result);
        tmp[slen] = '0' + n;
        tmp[slen + 1] = '\0';
        delete[] result;
        result = tmp;

        // fetch next digit from divisor
        pos--;
    }

    BigInteger tmp (result);
    tmp.m_sign = (a.Sign() == b.Sign()) ? true : false;
    tmp.RemoveLeadingZeros();
    return tmp;
}
开发者ID:peterloos,项目名称:Cpp_BigInteger,代码行数:52,代码来源:BigInteger.cpp

示例3: Test_BigMersennePrime

void Test_BigMersennePrime()
{
    BigInteger mersenne (1);
    BigInteger two (2);
    for (int i = 0; i < 11213; i ++)
        mersenne = mersenne * two;
    mersenne = mersenne - 1;

    cout << "Mersenne: " << endl << mersenne << endl;
    cout << "Number of Digits: " << mersenne.Cardinality() << endl;
}
开发者ID:peterloos,项目名称:Cpp_BigInteger,代码行数:11,代码来源:Program.cpp


注:本文中的BigInteger::Cardinality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。