Gerald wrote:

Recently, my program need to be run in embeded enviroment, and I cann't

use standard library.

I don't think that this is a reasonable argument for not using the

standard library! In particular, I know that there is at least one

standard library targeted also at embedded systems: the Dinkumware

library is available in a version tailored to embedded systems

(although I personally don't see any justification at all in EC++...).

See <http://www.dinkumware.com/>. The prices are definitely in a

range where it comes much cheaper to buy the library than provide a

quality implementation of even a single trigonometric function.

But I need to use arctan(x), so I implement it

like the following:

I haven't implemented these functions myself and thus I might be

entirely wrong about how I think these functions are implemented.

Still, my understanding is that they are implemented very different

from how you tried to implement them. The basic approach is something

like this:

1. Translate the function argument(s) to a minimal basic area (this

is almost certainly not the correct term but I don't know the

correct term). My maths is rather rusty but I think for arctan(x)

the basic area is the range [0, 1]: all other values can be

derived from an appropriate argument:

- x < 0: arctan(x) = -arctan(-x)

- 1 < x: arctan(1/x) = pi/2 - arctan(x)

(actually, you already do this part...)

2. For the values in basic area you look up the subrange your value

is located in. Each subrange is associated with an approximation

function which is just a suitably parameterized polynomial of a

relatively small degree which can be evaluated reasonably fast.

The real tricky thing is to determine suitable subranges and the

parameters for their approximating polynomials. I have no idea

at all how this done.

--

<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>

<http://www.eai-systems.com> - Efficient Artificial Intelligence