Post Reply 
(Free42) roundoff for complex SQRT
02-12-2021, 09:35 PM
Post: #24
RE: (Free42) roundoff for complex SQRT
That's what I was thinking of doing at first, but then you suggested the 48G algorithm, and I implemented that instead. There is no check for pure imaginary.

free42/common/core_commands6.cc

Code:
static int mappable_sqrt_c(phloat xre, phloat xim, phloat *yre, phloat *yim) {
    if (xre == 0 && xim == 0) {
        *yre = 0;
        *yim = 0;
        return ERR_NONE;
    }

    phloat r = hypot(xre, xim);
    phloat a = sqrt((r + fabs(xre)) / 2);
    phloat b = xim / (a * 2);

    if (p_isinf(a)) {
        xre /= 100;
        xim /= 100;
        r = hypot(xre, xim);
        a = sqrt((r + fabs(xre)) / 2);
        b = xim / (a * 2);
        a *= 10;
        b *= 10;
    }

    if (xre >= 0) {
        *yre = a;
        *yim = b;
    } else if (b >= 0) {
        *yre = b;
        *yim = a;
    } else {
        *yre = -b;
        *yim = -a;
    }
    return ERR_NONE;
}
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (Free42) roundoff for complex SQRT - Thomas Okken - 02-12-2021 09:35 PM



User(s) browsing this thread: 1 Guest(s)