简体   繁体   中英

Horner's rule using fixed point arithmetic in C

I am having a tough time tracking down the radix point for this following Horner's rule using fixed point arithmetic.

int16_t horner(int16_t q)
{
    const int16_t c0 = 0x0033;
    const int16_t c1 = 0x0055;
    const int16_t c2 = 0x001C;
    const int16_t c3 = 0x0048;
    const int16_t c4 = 0x0200;

    horner_rule = c0 + q * (c1 - q * (c2 + q * (c3 - q * c4)));

    return horner_rule;
}

Where c0 , c1 , etc. are different 16-bit signed coefficients, q is the value that I would like to evaluate at ( q is taken as an input and shifted to 16-bit signed format). All these values are already shifted into signed 16-bit format. I have implemented this in floating point arithmetic and it just works fine.

My question is, how shall I proceed to get my desired value maintaining the radix point and keeping the overflow in control?

First thing is to determine the domain and codomain of the polynomial and the partial ones. Then you can adjust the shifts to minimize the truncation error while avoiding overflows.

If you need to automate this process, you will have to find the minima and maxima of all these polynomials, which requires solving for the real roots.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM