Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You mean if you insert x->ix and N->2^N and use exponentiation by squaring? Then you get

    fun cis(x) {
        c, s <- 1, x >> N
        for 0 .. N-1 {
            c, s <- c*c - s*s, c*s << 1
        return c, s
    }
By comparison, CORDIC has only additions and shifts in the loop. CORDIC is also online in the sense that you don't need to know N up front, you can keep iteratively improving your approximation until you reach the limit of numeric precision. But with this function you need to know N up front.

If we're talking about fixed-point numbers, the initial assignment of s <- x>>N here is also scary since it is the only place in which x feeds into the algorithm and the shift means that the only a small number of the bits of x are actually used in the calculation. In the worst case, if you increased N a lot in the hope of getting more accuracy you could shift all the bits of x off and get the answer 1, 0 for every angle.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: