tapfunc.cpp

来自「任意精度计算的实现」· C++ 代码 · 共 67 行

CPP
67
字号
#include "ap.h"
#include "tapfloat.h"


// Overloaded tapfloat functions

// Positive integer power
apfloat pow (tapfloat base, unsigned long exp)
{
    int d = 0;
    apfloat b, r;

    if (!exp) return 1;

    if (!(exp & 1))
    {
        b = base * base;
        exp >>= 1;
        d = 1;
    }
    else
    {
        b = 1 * base;
    }

    while (!(exp & 1))
    {
        b *= b;
        exp >>= 1;
        d = 1;
    }
    r = b;

   if (exp >> 1 && d) base = transform (b);

    while (exp >>= 1)
    {
        b = base * base;
        base = transform (b);
        if (exp & 1) r = r * base;
    }

    return r;
}

apfloat pow (tapfloat base, unsigned exp)
{
    return pow (base, (unsigned long) exp);
}

// Integer power
apfloat pow (tapfloat base, long exp)
{
    if (exp < 0)
        return invroot (pow (base, (unsigned long) -exp), 1);
    else
        return pow (base, (unsigned long) exp);
}

apfloat pow (tapfloat base, int exp)
{
    if (exp < 0)
        return invroot (pow (base, (unsigned long) -exp), 1);
    else
        return pow (base, (unsigned long) exp);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?