Exemple #1
0
    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;
        }
    }
Exemple #2
0
    Number fabs(const Number& num1)
    {
        switch (num1.type())
        {
        case Number::INTEGER:
            {
                integer_type i = b_mp::abs(num1.get_i());
                return Number(i);
            }

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

        case Number::RATIONAL:
            {
                rational_type r = b_mp::abs(num1.get_r());
                return Number(r);
            }

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

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