Logo Search packages:      
Sourcecode: inkscape version File versions

SBasis Geom::sqrt ( SBasis const &  a,
int  k 
)

Compute the sqrt of a

Parameters:
a sbasis functions
Returns:
sbasis

\[ \sqrt{a} \]

It is recommended to use the piecewise version unless you have good reason. TODO: convert int k to unsigned k, and remove cast

Definition at line 370 of file sbasis.cpp.

                                    {
    SBasis c;
    if(a.isZero() || k == 0)
        return c;
    c.resize(k, Linear(0,0));
    c[0] = Linear(std::sqrt(a[0][0]), std::sqrt(a[0][1]));
    SBasis r = a - multiply(c, c); // remainder

    for(unsigned i = 1; i <= (unsigned)k && i<r.size(); i++) {
        Linear ci(r[i][0]/(2*c[0][0]), r[i][1]/(2*c[0][1]));
        SBasis cisi = shift(ci, i);
        r -= multiply(shift((c*2 + cisi), i), SBasis(ci));
        r.truncate(k+1);
        c += cisi;
        if(r.tailError(i) == 0) // if exact
            break;
    }

    return c;
}


Generated by  Doxygen 1.6.0   Back to index