コード例 #1
0
ファイル: PmpNumber.cpp プロジェクト: wyrover/Calc-H
    Number ceil(const Number& num1)
    {
        switch (num1.type())
        {
        case Number::INTEGER:
            return num1;

        case Number::FLOATING:
            {
                floating_type f = b_mp::ceil(num1.get_f());
                return Number(f);
            }

        case Number::RATIONAL:
            return -pmp::floor(-num1);

#ifndef PMP_DISABLE_VECTOR
        case Number::VECTOR:
            {
                vector_type v = num1.get_v();
                for (size_t i = 0; i < v.size(); ++i)
                {
                    v[i] = ceil(v[i]);
                }
                return Number(v);
            }
#endif

        default:
            assert(0);
            return 0;
        }
    }
コード例 #2
0
ファイル: PmpNumber.cpp プロジェクト: wyrover/Calc-H
    int Number::compare(const Number& num) const
    {
#ifndef PMP_DISABLE_VECTOR
        if (is_v() || num.is_v())
        {
            bool comparisons[3];
            compare(num, comparisons);
            if (comparisons[0])      return -1;
            else if (comparisons[1]) return 0;
            else if (comparisons[2]) return 1;
            else return -2;
        }
#endif

        floating_type f;
        switch (type())
        {
        case Number::INTEGER:
            switch (num.type())
            {
            case Number::INTEGER:
                return get_i().compare(num.get_i());

            case Number::FLOATING:
                f = to_f();
                return f.compare(num.get_f());

            case Number::RATIONAL:
                f = to_f();
                return f.compare(num.to_f());

            default:
                assert(0);
                return 0;
            }

        case Number::FLOATING:
            switch (num.type())
            {
            case Number::INTEGER:
                f = num.to_f();
                return get_f().compare(f);

            case Number::FLOATING:
                return get_f().compare(num.get_f());

            case Number::RATIONAL:
                return get_f().compare(num.to_f());

            default:
                assert(0);
                return 0;
            }

        case Number::RATIONAL:
            switch (num.type())
            {
            case Number::INTEGER:
                f = num.to_f();
                return to_f().compare(f);

            case Number::FLOATING:
                return to_f().compare(num.get_f());

            case Number::RATIONAL:
                return to_f().compare(num.to_f());

            default:
                assert(0);
                return 0;
            }

        default:
            assert(0);
            return 0;
        }
    }